mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
GH-89091: raise RuntimeWarning
for unawaited async generator methods (#104611)
This commit is contained in:
parent
46857d0b2a
commit
7fc542c88d
9 changed files with 96 additions and 2 deletions
|
@ -415,8 +415,9 @@ class AsyncGenTest(unittest.TestCase):
|
|||
self.assertIsInstance(g.ag_frame, types.FrameType)
|
||||
self.assertFalse(g.ag_running)
|
||||
self.assertIsInstance(g.ag_code, types.CodeType)
|
||||
|
||||
self.assertTrue(inspect.isawaitable(g.aclose()))
|
||||
aclose = g.aclose()
|
||||
self.assertTrue(inspect.isawaitable(aclose))
|
||||
aclose.close()
|
||||
|
||||
|
||||
class AsyncGenAsyncioTest(unittest.TestCase):
|
||||
|
@ -1693,5 +1694,38 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
self.loop.run_until_complete(run())
|
||||
|
||||
|
||||
class TestUnawaitedWarnings(unittest.TestCase):
|
||||
def test_asend(self):
|
||||
async def gen():
|
||||
yield 1
|
||||
|
||||
msg = f"coroutine method 'asend' of '{gen.__qualname__}' was never awaited"
|
||||
with self.assertWarnsRegex(RuntimeWarning, msg):
|
||||
g = gen()
|
||||
g.asend(None)
|
||||
gc_collect()
|
||||
|
||||
def test_athrow(self):
|
||||
async def gen():
|
||||
yield 1
|
||||
|
||||
msg = f"coroutine method 'athrow' of '{gen.__qualname__}' was never awaited"
|
||||
with self.assertWarnsRegex(RuntimeWarning, msg):
|
||||
g = gen()
|
||||
g.athrow(RuntimeError)
|
||||
gc_collect()
|
||||
|
||||
def test_aclose(self):
|
||||
async def gen():
|
||||
yield 1
|
||||
|
||||
msg = f"coroutine method 'aclose' of '{gen.__qualname__}' was never awaited"
|
||||
with self.assertWarnsRegex(RuntimeWarning, msg):
|
||||
g = gen()
|
||||
g.aclose()
|
||||
gc_collect()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue