mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-126091: Always link generator frames when propagating a thrown-in exception through a yield-from chain (#126092)
Always link generator frames when propagating a thrown-in exception through a yield-from chain.
This commit is contained in:
parent
3fafc1bd83
commit
e8bb053941
3 changed files with 35 additions and 7 deletions
|
@ -758,7 +758,8 @@ class GeneratorStackTraceTest(unittest.TestCase):
|
|||
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_'):
|
||||
if (name.startswith('check_') or name.startswith('call_')
|
||||
or name.startswith('test')):
|
||||
break
|
||||
|
||||
names.append(name)
|
||||
|
@ -799,6 +800,25 @@ class GeneratorStackTraceTest(unittest.TestCase):
|
|||
|
||||
self.check_yield_from_example(call_throw)
|
||||
|
||||
def test_throw_with_yield_from_custom_generator(self):
|
||||
|
||||
class CustomGen:
|
||||
def __init__(self, test):
|
||||
self.test = test
|
||||
def throw(self, *args):
|
||||
self.test.check_stack_names(sys._getframe(), ['throw', 'g'])
|
||||
def __iter__(self):
|
||||
return self
|
||||
def __next__(self):
|
||||
return 42
|
||||
|
||||
def g(target):
|
||||
yield from target
|
||||
|
||||
gen = g(CustomGen(self))
|
||||
gen.send(None)
|
||||
gen.throw(RuntimeError)
|
||||
|
||||
|
||||
class YieldFromTests(unittest.TestCase):
|
||||
def test_generator_gi_yieldfrom(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue