railtracks.context
def
put(key: str, value: Any):
306def put( 307 key: str, 308 value: Any, 309): 310 """ 311 Set a value in the context. 312 313 Args: 314 key (str): The key to set. 315 value (Any): The value to set. 316 """ 317 context = safe_get_runner_context() 318 context.external_context.put(key, value)
Set a value in the context.
Arguments:
- key (str): The key to set.
- value (Any): The value to set.
def
get(key: str, /, default: Optional[Any] = None):
285def get( 286 key: str, 287 /, 288 default: Any | None = None, 289): 290 """ 291 Get a value from context 292 293 Args: 294 key (str): The key to retrieve. 295 default (Any | None): The default value to return if the key does not exist. If set to None and the key does not exist, a KeyError will be raised. 296 Returns: 297 Any: The value associated with the key, or the default value if the key does not exist. 298 299 Raises: 300 KeyError: If the key does not exist and no default value is provided. 301 """ 302 context = safe_get_runner_context() 303 return context.external_context.get(key, default=default)
Get a value from context
Arguments:
- key (str): The key to retrieve.
- default (Any | None): The default value to return if the key does not exist. If set to None and the key does not exist, a KeyError will be raised.
Returns:
Any: The value associated with the key, or the default value if the key does not exist.
Raises:
- KeyError: If the key does not exist and no default value is provided.
def
update(data: dict[str, typing.Any]):
321def update(data: dict[str, Any]): 322 """ 323 Sets the values in the context. If the context already has values, this will overwrite them, but it will not delete any existing keys. 324 325 Args: 326 data (dict[str, Any]): The data to update the context with. 327 """ 328 context = safe_get_runner_context() 329 context.external_context.update(data)
Sets the values in the context. If the context already has values, this will overwrite them, but it will not delete any existing keys.
Arguments:
- data (dict[str, Any]): The data to update the context with.
def
delete(key: str):
332def delete(key: str): 333 """ 334 Delete a key from the context. 335 336 Args: 337 key (str): The key to delete. 338 339 Raises: 340 KeyError: If the key does not exist. 341 """ 342 context = safe_get_runner_context() 343 context.external_context.delete(key)
Delete a key from the context.
Arguments:
- key (str): The key to delete.
Raises:
- KeyError: If the key does not exist.
def
keys() -> KeysView[str]:
346def keys() -> KeysView[str]: 347 """ 348 Get the keys of the context. 349 350 Returns: 351 KeysView[str]: The keys in the context. 352 """ 353 context = safe_get_runner_context() 354 return context.external_context.keys()
Get the keys of the context.
Returns:
KeysView[str]: The keys in the context.