diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-01-20 23:06:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-20 23:06:40 (GMT) |
commit | 5cadd3fe3aead1b5bee1438dc03383d6739d4209 (patch) | |
tree | f43a6fad9c24094f3432b275ebc2bd57c4cb882b /Lib/test | |
parent | 6aeed01901d020363e383821b38614816d0b4032 (diff) | |
download | cpython-5cadd3fe3aead1b5bee1438dc03383d6739d4209.zip cpython-5cadd3fe3aead1b5bee1438dc03383d6739d4209.tar.gz cpython-5cadd3fe3aead1b5bee1438dc03383d6739d4209.tar.bz2 |
bpo-39386: Prevent double awaiting of async iterator (GH-18081)
(cherry picked from commit a96e06db77dcbd3433d39761ddb4615d7d96284a)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_asyncgen.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index 58d8aee..24b20be 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -1128,6 +1128,42 @@ class AsyncGenAsyncioTest(unittest.TestCase): self.assertEqual([], messages) + def test_async_gen_await_anext_twice(self): + async def async_iterate(): + yield 1 + yield 2 + + async def run(): + it = async_iterate() + nxt = it.__anext__() + await nxt + with self.assertRaisesRegex( + RuntimeError, + r"cannot reuse already awaited __anext__\(\)/asend\(\)" + ): + await nxt + + await it.aclose() # prevent unfinished iterator warning + + self.loop.run_until_complete(run()) + + def test_async_gen_await_aclose_twice(self): + async def async_iterate(): + yield 1 + yield 2 + + async def run(): + it = async_iterate() + nxt = it.aclose() + await nxt + with self.assertRaisesRegex( + RuntimeError, + r"cannot reuse already awaited aclose\(\)/athrow\(\)" + ): + await nxt + + self.loop.run_until_complete(run()) + if __name__ == "__main__": unittest.main() |