mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-39606: allow closing async generators that are already closed (GH-18475)
The fix for [bpo-39386](https://bugs.python.org/issue39386) attempted to make it so you couldn't reuse a agen.aclose() coroutine object. It accidentally also prevented you from calling aclose() at all on an async generator that was already closed or exhausted. This commit fixes it so we're only blocking the actually illegal cases, while allowing the legal cases. The new tests failed before this patch. Also confirmed that this fixes the test failures we were seeing in Trio with Python dev builds: https://github.com/python-trio/trio/pull/1396 https://bugs.python.org/issue39606
This commit is contained in:
parent
7514f4f625
commit
925dc7fb1d
3 changed files with 41 additions and 6 deletions
|
@ -1128,7 +1128,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
|
||||
self.assertEqual([], messages)
|
||||
|
||||
def test_async_gen_await_anext_twice(self):
|
||||
def test_async_gen_await_same_anext_coro_twice(self):
|
||||
async def async_iterate():
|
||||
yield 1
|
||||
yield 2
|
||||
|
@ -1147,7 +1147,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
def test_async_gen_await_aclose_twice(self):
|
||||
def test_async_gen_await_same_aclose_coro_twice(self):
|
||||
async def async_iterate():
|
||||
yield 1
|
||||
yield 2
|
||||
|
@ -1164,6 +1164,32 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
def test_async_gen_aclose_twice_with_different_coros(self):
|
||||
# Regression test for https://bugs.python.org/issue39606
|
||||
async def async_iterate():
|
||||
yield 1
|
||||
yield 2
|
||||
|
||||
async def run():
|
||||
it = async_iterate()
|
||||
await it.aclose()
|
||||
await it.aclose()
|
||||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
def test_async_gen_aclose_after_exhaustion(self):
|
||||
# Regression test for https://bugs.python.org/issue39606
|
||||
async def async_iterate():
|
||||
yield 1
|
||||
yield 2
|
||||
|
||||
async def run():
|
||||
it = async_iterate()
|
||||
async for _ in it:
|
||||
pass
|
||||
await it.aclose()
|
||||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue