Sometimes I need a dummy context manager that does nothing. It can then be used as a stand-in for a more useful, but optional, context manager. For example:
ctx_
Since Python 3.2, memoryview(b'') can be use as a no-op context manager. See https://docs.python.org/3/library/stdtypes.html#memoryview.release.
memoryview(b'')
Pros
No imports required
Works on 3.2+
Roughly twice as fast as contextlib.nullcontext
contextlib.nullcontext
Cons
# no-op