Skip to content

Commit

Permalink
clear frame locals
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Jan 11, 2024
1 parent cb86103 commit f016be1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions better_exchook.py
Expand Up @@ -47,7 +47,7 @@
Also see the demo/tests at the end.
"""

from __future__ import print_function
from __future__ import annotations

import sys
import os
Expand Down Expand Up @@ -1224,6 +1224,7 @@ def _try_set(old, prefix, func):
output(color(" no locals", color.fg_colors[0]))
else:
output(color(" -- code not available --", color.fg_colors[0]))
f.f_locals.clear() # https://github.com/python/cpython/issues/113939
if isframe(_tb):
_tb = _tb.f_back
elif is_stack_summary(_tb):
Expand Down Expand Up @@ -1496,8 +1497,10 @@ def get_func_from_code_object(co, frame=None):
_attr_name = "__code__" if PY3 else "func_code"
if frame:
func_name = frame.f_code.co_name
if "self" in frame.f_locals:
candidate = getattr(frame.f_locals["self"].__class__, func_name, None)
frame_self = frame.f_locals.get("self")
frame.f_locals.clear() # https://github.com/python/cpython/issues/113939
if frame_self is not None:
candidate = getattr(frame_self.__class__, func_name, None)
if candidate and (getattr(candidate, _attr_name, None) is co or isinstance(co, DummyFrame)):
return candidate
try:
Expand Down

0 comments on commit f016be1

Please sign in to comment.