gh-132385: Fix instance error suggestions trigger potential exceptions in traceback (#132387)

This commit is contained in:
sobolevn 2025-05-02 15:52:59 +03:00 committed by GitHub
parent 20f8ed595d
commit 641253cfac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View file

@ -1636,7 +1636,11 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
# has the wrong name as attribute
if 'self' in frame.f_locals:
self = frame.f_locals['self']
if hasattr(self, wrong_name):
try:
has_wrong_name = hasattr(self, wrong_name)
except Exception:
has_wrong_name = False
if has_wrong_name:
return f"self.{wrong_name}"
try: