diff options
author | Tom Gringauz <tomgrin10@gmail.com> | 2020-11-09 12:34:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 12:34:07 (GMT) |
commit | a117167d8dc8fa673a4646f509551c7950f824e5 (patch) | |
tree | 14ed56dc05c33931932c8e911a76b374d9fd74b1 /Lib/contextlib.py | |
parent | 97e8b1eaeaf3aa325c84ff2e13417c30414d0269 (diff) | |
download | cpython-a117167d8dc8fa673a4646f509551c7950f824e5.zip cpython-a117167d8dc8fa673a4646f509551c7950f824e5.tar.gz cpython-a117167d8dc8fa673a4646f509551c7950f824e5.tar.bz2 |
bpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r-- | Lib/contextlib.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 56b4968..a0b523c 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -704,7 +704,7 @@ class AsyncExitStack(_BaseExitStack, AbstractAsyncContextManager): return received_exc and suppressed_exc -class nullcontext(AbstractContextManager): +class nullcontext(AbstractContextManager, AbstractAsyncContextManager): """Context manager that does no additional processing. Used as a stand-in for a normal context manager, when a particular @@ -723,3 +723,9 @@ class nullcontext(AbstractContextManager): def __exit__(self, *excinfo): pass + + async def __aenter__(self): + return self.enter_result + + async def __aexit__(self, *excinfo): + pass |