Skip to content

gh-93592: Port regression test to main branch #96208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pickle
import sys
import types
import traceback
import unittest
import warnings
from test import support
Expand Down Expand Up @@ -2207,6 +2208,29 @@ async def f():
with self.assertWarns(RuntimeWarning):
gen.cr_frame.clear()

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)


@unittest.skipIf(
support.is_emscripten or support.is_wasi,
Expand Down