Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
update traceback module to use the new arg
  • Loading branch information
iritkatriel committed Nov 6, 2023
commit 0e570d069f7d87b56f67fce27019a8a19dbb0768
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