From a117167d8dc8fa673a4646f509551c7950f824e5 Mon Sep 17 00:00:00 2001 From: Tom Gringauz Date: Mon, 9 Nov 2020 14:34:07 +0200 Subject: bpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870) Co-authored-by: Andrew Svetlov --- Lib/contextlib.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 56b4968118..a0b523c96f 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 -- cgit v1.2.1