mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
bpo-39386: Prevent double awaiting of async iterator (GH-18081)
This commit is contained in:
parent
2c49becc69
commit
a96e06db77
3 changed files with 49 additions and 4 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue