mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
GH-117714: implement athrow().close() and asend().close() using throw (GH-117906)
* GH-117714: replace athrow().close() and asend().close() stubs with implimentations * test athrow().close() and asend().close() raises RuntimeError * 📜🤖 Added by blurb_it. * Update Objects/genobject.c Co-authored-by: Petr Viktorin <encukou@gmail.com> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
1ff626ebda
commit
e5c699280d
3 changed files with 87 additions and 4 deletions
|
@ -571,6 +571,54 @@ class AsyncGenTest(unittest.TestCase):
|
|||
self.assertTrue(inspect.isawaitable(aclose))
|
||||
aclose.close()
|
||||
|
||||
def test_async_gen_asend_close_runtime_error(self):
|
||||
import types
|
||||
|
||||
@types.coroutine
|
||||
def _async_yield(v):
|
||||
return (yield v)
|
||||
|
||||
async def agenfn():
|
||||
try:
|
||||
await _async_yield(None)
|
||||
except GeneratorExit:
|
||||
await _async_yield(None)
|
||||
return
|
||||
yield
|
||||
|
||||
agen = agenfn()
|
||||
gen = agen.asend(None)
|
||||
gen.send(None)
|
||||
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
|
||||
gen.close()
|
||||
|
||||
def test_async_gen_athrow_close_runtime_error(self):
|
||||
import types
|
||||
|
||||
@types.coroutine
|
||||
def _async_yield(v):
|
||||
return (yield v)
|
||||
|
||||
class MyExc(Exception):
|
||||
pass
|
||||
|
||||
async def agenfn():
|
||||
try:
|
||||
yield
|
||||
except MyExc:
|
||||
try:
|
||||
await _async_yield(None)
|
||||
except GeneratorExit:
|
||||
await _async_yield(None)
|
||||
|
||||
agen = agenfn()
|
||||
with self.assertRaises(StopIteration):
|
||||
agen.asend(None).send(None)
|
||||
gen = agen.athrow(MyExc)
|
||||
gen.send(None)
|
||||
with self.assertRaisesRegex(RuntimeError, "coroutine ignored GeneratorExit"):
|
||||
gen.close()
|
||||
|
||||
|
||||
class AsyncGenAsyncioTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue