1# Ported from python 3.7 contextlib.py 2class nullcontext(object): 3 """Context manager that does no additional processing. 4 Used as a stand-in for a normal context manager, when a particular 5 block of code is only sometimes used with a normal context manager: 6 cm = optional_cm if condition else nullcontext() 7 with cm: 8 # Perform operation, using optional_cm if condition is True 9 """ 10 11 def __init__(self, enter_result=None): 12 self.enter_result = enter_result 13 14 def __enter__(self): 15 return self.enter_result 16 17 def __exit__(self, *excinfo): 18 pass 19