MCPcopy Index your code
hub / github.com/RustPython/RustPython / nullcontext

Class nullcontext

Lib/contextlib.py:775–799  ·  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

773
774
775class nullcontext(AbstractContextManager, AbstractAsyncContextManager):
776 """Context manager that does no additional processing.
777
778 Used as a stand-in for a normal context manager, when a particular
779 block of code is only sometimes used with a normal context manager:
780
781 cm = optional_cm if condition else nullcontext()
782 with cm:
783 # Perform operation, using optional_cm if condition is True
784 """
785
786 def __init__(self, enter_result=None):
787 self.enter_result = enter_result
788
789 def __enter__(self):
790 return self.enter_result
791
792 def __exit__(self, *excinfo):
793 pass
794
795 async def __aenter__(self):
796 return self.enter_result
797
798 async def __aexit__(self, *excinfo):
799 pass
800
801
802class chdir(AbstractContextManager):

Callers 6

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