New submission from STINNER Victor: traceback.clear_frames(): "Clears the local variables of all the stack frames in a traceback tb by calling the clear() method of each frame object." https://docs.python.org/dev/library/traceback.html#traceback.clear_frames
That's wrong: it only calls frame.clear() on the top frame of each traceback object. Output of attached clear_frames_bug.py script: --- locals: frame locals {'z': 3} frame locals {'y': 2} frame locals {'x': 1} clear_frames() locals: frame locals {} frame locals {'y': 2} frame locals {'x': 1} --- As you can see, only the locals of the func3() frame, where the exception was raised, is clear. Locals of other frames are not cleared. Attached PR fixes the issue. Output with the fix: --- locals: frame locals {'z': 3} frame locals {'y': 2} frame locals {'x': 1} clear_frames() locals: frame locals {} frame locals {} frame locals {} --- ---------- messages: 301111 nosy: haypo priority: normal severity: normal status: open title: traceback.clear_frames() doesn't clear *all* frames versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31321> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com