[3.10] GH--93592: Fix frame chain when throwing exceptions into coroutines (GH-95207)

This commit is contained in:
Kristján Valur Jónsson 2022-08-23 11:23:39 +00:00 committed by GitHub
parent 9c34d644ed
commit d23ab79952
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View file

@ -4,6 +4,7 @@
import pickle
import sys
import types
import traceback
import unittest
import warnings
from test import support
@ -2119,6 +2120,29 @@ async def run_gen():
return 'end'
self.assertEqual(run_async(run_gen()), ([], 'end'))
def test_stack_in_coroutine_throw(self):
# Regression test for https://github.com/python/cpython/issues/93592
async def a():
return await b()
async def b():
return await c()
@types.coroutine
def c():
try:
# traceback.print_stack()
yield len(traceback.extract_stack())
except ZeroDivisionError:
# traceback.print_stack()
yield len(traceback.extract_stack())
coro = a()
len_send = coro.send(None)
len_throw = coro.throw(ZeroDivisionError)
# before fixing, visible stack from throw would be shorter than from send.
self.assertEqual(len_send, len_throw)
class CoroAsyncIOCompatTest(unittest.TestCase):