FallbackContext
Context workaround.
The built-in @contextmanager utility does not work well
when wrapping other contexts, as the traceback is wrong when
the wrapped context raises.
Attributes
| Attribute | Type | Description |
|---|---|---|
| provided | any | The existing resource or connection to be returned directly if it is not None. |
| fallback | callable | A callable that returns a context manager to be used if the provided resource is None. |
| fb_args | tuple | Positional arguments to be passed to the fallback callable when initializing the context. |
| fb_kwargs | dict | Keyword arguments to be passed to the fallback callable when initializing the context. |
| _context | any = None | Internal storage for the active context manager instance created by the fallback callable. |
Constructor
Signature
def FallbackContext(
provided: Any,
fallback: callable,
*fb_args: tuple,
**fb_kwargs: dict
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| provided | Any | An existing value to be returned if it is not None. |
| fallback | callable | A callable that returns a context manager to be used if provided is None. |
| *fb_args | tuple | Positional arguments to pass to the fallback callable. |
| **fb_kwargs | dict | Keyword arguments to pass to the fallback callable. |