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
| 756 | |
| 757 | |
| 758 | class 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 | |
| 785 | class chdir(AbstractContextManager): |
no outgoing calls
searching dependent graphs…