mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-99139: Improve NameError error suggestion for instances (#99140)
This commit is contained in:
parent
a0bc75e2fd
commit
99e2e60cb2
7 changed files with 92 additions and 0 deletions
|
@ -1037,6 +1037,16 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
|
|||
+ list(frame.f_globals)
|
||||
+ list(frame.f_builtins)
|
||||
)
|
||||
|
||||
# Check first if we are in a method and the instance
|
||||
# has the wrong name as attribute
|
||||
if 'self' in frame.f_locals:
|
||||
self = frame.f_locals['self']
|
||||
if hasattr(self, wrong_name):
|
||||
return f"self.{wrong_name}"
|
||||
|
||||
# Compute closest match
|
||||
|
||||
if len(d) > _MAX_CANDIDATE_ITEMS:
|
||||
return None
|
||||
wrong_name_len = len(wrong_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue