Skip to content

Commit

Permalink
update traceback module to use the new arg
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Nov 6, 2023
1 parent af0b965 commit 0e570d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,25 @@ def inner():
# Local variable dict should now be empty.
self.assertEqual(len(inner_frame.f_locals), 0)

def test_do_not_clear_frame_of_suspended_generator(self):
# See gh-79932

def f():
try:
raise TypeError
except Exception as e:
yield e
yield 42

def g():
yield from f()

gen = g()
e = next(gen)
self.assertIsInstance(e, TypeError)
traceback.clear_frames(e.__traceback__)
self.assertEqual(next(gen), 42)

def test_extract_stack(self):
def extract():
return traceback.extract_stack()
Expand Down
2 changes: 1 addition & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def clear_frames(tb):
"Clear all references to local variables in the frames of a traceback."
while tb is not None:
try:
tb.tb_frame.clear()
tb.tb_frame.clear(True)
except RuntimeError:
# Ignore the exception raised if the frame is still executing.
pass
Expand Down

0 comments on commit 0e570d0

Please sign in to comment.