Skip to content

Commit acd7841

Browse files
Port regression test for issue GH-93592 (GH-96208) (GH-96313)
1 parent 315807d commit acd7841

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/test/test_coroutines.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pickle
55
import sys
66
import types
7+
import traceback
78
import unittest
89
import warnings
910
from test import support
@@ -2207,6 +2208,29 @@ async def f():
22072208
with self.assertWarns(RuntimeWarning):
22082209
gen.cr_frame.clear()
22092210

2211+
def test_stack_in_coroutine_throw(self):
2212+
# Regression test for https://github.com/python/cpython/issues/93592
2213+
async def a():
2214+
return await b()
2215+
2216+
async def b():
2217+
return await c()
2218+
2219+
@types.coroutine
2220+
def c():
2221+
try:
2222+
# traceback.print_stack()
2223+
yield len(traceback.extract_stack())
2224+
except ZeroDivisionError:
2225+
# traceback.print_stack()
2226+
yield len(traceback.extract_stack())
2227+
2228+
coro = a()
2229+
len_send = coro.send(None)
2230+
len_throw = coro.throw(ZeroDivisionError)
2231+
# before fixing, visible stack from throw would be shorter than from send.
2232+
self.assertEqual(len_send, len_throw)
2233+
22102234

22112235
@unittest.skipIf(
22122236
support.is_emscripten or support.is_wasi,

0 commit comments

Comments
 (0)