Skip to content

Commit 0e570d0

Browse files
committed
update traceback module to use the new arg
1 parent af0b965 commit 0e570d0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Lib/test/test_traceback.py

+19
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,25 @@ def inner():
25182518
# Local variable dict should now be empty.
25192519
self.assertEqual(len(inner_frame.f_locals), 0)
25202520

2521+
def test_do_not_clear_frame_of_suspended_generator(self):
2522+
# See gh-79932
2523+
2524+
def f():
2525+
try:
2526+
raise TypeError
2527+
except Exception as e:
2528+
yield e
2529+
yield 42
2530+
2531+
def g():
2532+
yield from f()
2533+
2534+
gen = g()
2535+
e = next(gen)
2536+
self.assertIsInstance(e, TypeError)
2537+
traceback.clear_frames(e.__traceback__)
2538+
self.assertEqual(next(gen), 42)
2539+
25212540
def test_extract_stack(self):
25222541
def extract():
25232542
return traceback.extract_stack()

Lib/traceback.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def clear_frames(tb):
251251
"Clear all references to local variables in the frames of a traceback."
252252
while tb is not None:
253253
try:
254-
tb.tb_frame.clear()
254+
tb.tb_frame.clear(True)
255255
except RuntimeError:
256256
# Ignore the exception raised if the frame is still executing.
257257
pass

0 commit comments

Comments
 (0)