__init__

LayeredContext.__init__(wrapped_class: K, max_layers: Optional[int] = 1, fail: bool = False)[source]

Construct a LayeredContext instance, wrapping the context manager class instance or func:contextlib.contextmanager manager function wrapped_class.

Parameters
  • wrapped_class (K|object) – A context manager class or contextlib.contextmanager() manager function to wrap

  • max_layers (int) – Maximum layers of (async) with blocks before silently consuming further attempts to enter/exit the context manager for wrapped_class

  • fail (bool) – (default: False) When True, will raise NestedContextException when an enter() call is going to cause more than max_layers context manager layers to be active.