Skip to content

Commit f016be1

Browse files
committed
clear frame locals
python/cpython#113939
1 parent cb86103 commit f016be1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

better_exchook.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Also see the demo/tests at the end.
4848
"""
4949

50-
from __future__ import print_function
50+
from __future__ import annotations
5151

5252
import sys
5353
import os
@@ -1224,6 +1224,7 @@ def _try_set(old, prefix, func):
12241224
output(color(" no locals", color.fg_colors[0]))
12251225
else:
12261226
output(color(" -- code not available --", color.fg_colors[0]))
1227+
f.f_locals.clear() # https://github.com/python/cpython/issues/113939
12271228
if isframe(_tb):
12281229
_tb = _tb.f_back
12291230
elif is_stack_summary(_tb):
@@ -1496,8 +1497,10 @@ def get_func_from_code_object(co, frame=None):
14961497
_attr_name = "__code__" if PY3 else "func_code"
14971498
if frame:
14981499
func_name = frame.f_code.co_name
1499-
if "self" in frame.f_locals:
1500-
candidate = getattr(frame.f_locals["self"].__class__, func_name, None)
1500+
frame_self = frame.f_locals.get("self")
1501+
frame.f_locals.clear() # https://github.com/python/cpython/issues/113939
1502+
if frame_self is not None:
1503+
candidate = getattr(frame_self.__class__, func_name, None)
15011504
if candidate and (getattr(candidate, _attr_name, None) is co or isinstance(co, DummyFrame)):
15021505
return candidate
15031506
try:

0 commit comments

Comments
 (0)