You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add the attribute that describe which operation cause NameError in NameError object #140779
assert isinstance(exc_value, NameError)
# find most recent frame
if tb is None:
return None
while tb.tb_next is not None:
tb = tb.tb_next
frame = tb.tb_frame
d = (
list(frame.f_locals)
+ list(frame.f_globals)
+ list(frame.f_builtins)
)
d = [x for x in d if isinstance(x, str)]
If we can add the attribute in NameError (e.g. "op") to describe which operation cause the NameError, the suggestion will be more exactly:
assert isinstance(exc_value, NameError)
# find most recent frame
if tb is None:
return None
while tb.tb_next is not None:
tb = tb.tb_next
frame = tb.tb_frame
if getattr(exc_value, "op", "getting") == "deleting":
d = (list(frame.f_locals)
+ list(frame.f_globals))
else:
d = (
list(frame.f_locals)
+ list(frame.f_globals)
+ list(frame.f_builtins)
)
d = [x for x in d if isinstance(x, str)]
By this way, the suggestion on NameError caused by deleting a variable won't possibly be a builtins name that user hasn't redefined it.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
I will close this one as a duplicate of #138890 because the use case is only for the special case of del. Also, I don't think this issue should have been opened because the DPO thread did not receive much support in the first place.
I personally don't want to expose the operation type in NameError. An alternative would be a subclass of NameError but it also has caveats that I'm not willing to support.
Activity
picnixz commentedon Oct 30, 2025
I will close this one as a duplicate of #138890 because the use case is only for the special case of
del. Also, I don't think this issue should have been opened because the DPO thread did not receive much support in the first place.I personally don't want to expose the operation type in
NameError. An alternative would be a subclass ofNameErrorbut it also has caveats that I'm not willing to support.