summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncgen.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-02-13 08:43:23 (GMT)
committerGitHub <noreply@github.com>2020-02-13 08:43:23 (GMT)
commit8dbdf5f275c6462bb522bcf3a29054239d72989d (patch)
tree6c0836e87e8f69904d215c2e19723d8e0a617724 /Lib/test/test_asyncgen.py
parenta00b5be5f71b702ab80b0a7c046485046aaae160 (diff)
downloadcpython-8dbdf5f275c6462bb522bcf3a29054239d72989d.zip
cpython-8dbdf5f275c6462bb522bcf3a29054239d72989d.tar.gz
cpython-8dbdf5f275c6462bb522bcf3a29054239d72989d.tar.bz2
[3.8] bpo-39606: allow closing async generators that are already closed (GH-18475) (GH-18501)
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 (cherry picked from commit 925dc7fb1d0db85dc137afa4cd14211bf0d67414) Co-authored-by: Nathaniel J. Smith <njs@pobox.com> https://bugs.python.org/issue39606 Automerge-Triggered-By: @njsmith
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r--Lib/test/test_asyncgen.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 24b20be..fb6321d 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -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()