stouputils.ctx.do_nothing module#

class DoNothing(*args: Any, **kwargs: Any)[source]#

Bases: AbstractBothContextManager[DoNothing]

Context manager that does nothing.

This is a no-op context manager that can be used as a placeholder or for conditional context management.

Different from contextlib.nullcontext because it handles args and kwargs, along with async context management.

Examples

>>> with DoNothing():
...     print("This will be printed normally")
This will be printed normally
>>> # Conditional context management
>>> some_condition = True
>>> ctx = DoNothing() if some_condition else Muffle()
>>> with ctx:
...     print("May or may not be printed depending on condition")
May or may not be printed depending on condition
_abc_impl = <_abc._abc_data object>#
NullContextManager#

Alias for DoNothing context manager