MCPcopy Index your code
hub / github.com/python/cpython / nullcontext

Class nullcontext

Lib/contextlib.py:758–782  ·  view source on GitHub ↗

Context manager that does no additional processing. Used as a stand-in for a normal context manager, when a particular block of code is only sometimes used with a normal context manager: cm = optional_cm if condition else nullcontext() with cm: # Perform operation, using op

Source from the content-addressed store, hash-verified

756
757
758class nullcontext(AbstractContextManager, AbstractAsyncContextManager):
759 """Context manager that does no additional processing.
760
761 Used as a stand-in for a normal context manager, when a particular
762 block of code is only sometimes used with a normal context manager:
763
764 cm = optional_cm if condition else nullcontext()
765 with cm:
766 # Perform operation, using optional_cm if condition is True
767 """
768
769 def __init__(self, enter_result=None):
770 self.enter_result = enter_result
771
772 def __enter__(self):
773 return self.enter_result
774
775 def __exit__(self, *excinfo):
776 pass
777
778 async def __aenter__(self):
779 return self.enter_result
780
781 async def __aexit__(self, *excinfo):
782 pass
783
784
785class chdir(AbstractContextManager):

Callers 7

delimit_ifMethod · 0.90
_find_wheel_pkg_dir_pipFunction · 0.90
test_nullcontextMethod · 0.85

Calls

no outgoing calls

Tested by 4

test_nullcontextMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…