mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
This commit is contained in:
parent
97e8b1eaea
commit
a117167d8d
4 changed files with 39 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
import asyncio
|
||||
from contextlib import aclosing, asynccontextmanager, AbstractAsyncContextManager, AsyncExitStack
|
||||
from contextlib import (
|
||||
asynccontextmanager, AbstractAsyncContextManager,
|
||||
AsyncExitStack, nullcontext, aclosing)
|
||||
import functools
|
||||
from test import support
|
||||
import unittest
|
||||
|
@ -537,5 +539,15 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
|
|||
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError)
|
||||
|
||||
|
||||
class TestAsyncNullcontext(unittest.TestCase):
|
||||
@_async_test
|
||||
async def test_async_nullcontext(self):
|
||||
class C:
|
||||
pass
|
||||
c = C()
|
||||
async with nullcontext(c) as c_in:
|
||||
self.assertIs(c_in, c)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue