8000 bpo-29590: fix stack trace for gen.throw() with yield from by cjerdonek · Pull Request #19896 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-29590: fix stack trace for gen.throw() with yield from #19896

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 2 commits into from
Jul 9, 2020
Merged
Changes from 1 commit
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
Next Next commit
Add failing test.
  • Loading branch information
cjerdonek committed May 4, 2020
commit 75baa966a13e383e522c96cca1b120c68cceb8a0
49 changes: 49 additions & 0 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,55 @@ def g():
gen.throw(ValueError)


class GeneratorStackTraceTest(unittest.TestCase):

def check_stack_names(self, frame, expected):
names = []
while frame:
name = frame.f_code.co_name
# Stop checking frames when we get to our test helper.
if name.startswith('check_') or name.startswith('call_'):
break

names.append(name)
frame = frame.f_back

self.assertEqual(names, expected)

def check_yield_from_example(self, call_method):
def f():
self.check_stack_names(sys._getframe(), ['f', 'g'])
try:
yield
except Exception:
pass
self.check_stack_names(sys._getframe(), ['f', 'g'])

def g():
self.check_stack_names(sys._getframe(), ['g'])
yield from f()
self.check_stack_names(sys._getframe(), ['g'])

gen = g()
gen.send(None)
try:
call_method(gen)
except StopIteration:
pass

def test_send_with_yield_from(self):
def call_send(gen):
gen.send(None)

self.check_yield_from_example(call_send)

def test_throw_with_yield_from(self):
def call_throw(gen):
gen.throw(RuntimeError)

self.check_yield_from_example(call_throw)


class YieldFromTests(unittest.TestCase):
def test_generator_gi_yieldfrom(self):
def a():
Expand Down
0