railtracks.context
def
put(key: str, value: Any) -> None:
314def put( 315 key: str, 316 value: Any, 317) -> None: 318 """ 319 Set a value in the context. 320 321 Args: 322 key (str): The key to set. 323 value (Any): The value to set. 324 """ 325 context = safe_get_runner_context() 326 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) -> Any:
293def get( 294 key: str, 295 /, 296 default: Any | None = None, 297) -> Any: 298 """ 299 Get a value from context 300 301 Args: 302 key (str): The key to retrieve. 303 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. 304 Returns: 305 Any: The value associated with the key, or the default value if the key does not exist. 306 307 Raises: 308 KeyError: If the key does not exist and no default value is provided. 309 """ 310 context = safe_get_runner_context() 311 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]) -> None:
329def update(data: dict[str, Any]) -> None: 330 """ 331 Sets the values in the context. If the context already has values, this will overwrite them, but it will not delete any existing keys. 332 333 Args: 334 data (dict[str, Any]): The data to update the context with. 335 """ 336 context = safe_get_runner_context() 337 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) -> None:
340def delete(key: str) -> None: 341 """ 342 Delete a key from the context. 343 344 Args: 345 key (str): The key to delete. 346 347 Raises: 348 KeyError: If the key does not exist. 349 """ 350 context = safe_get_runner_context() 351 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]:
354def keys() -> KeysView[str]: 355 """ 356 Get the keys of the context. 357 358 Returns: 359 KeysView[str]: The keys in the context. 360 """ 361 context = safe_get_runner_context() 362 return context.external_context.keys()
Get the keys of the context.
Returns:
KeysView[str]: The keys in the context.