-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-132385: Fix instance error suggestions potential exceptions in traceback
#132387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Lib/traceback.py
Outdated
if hasattr(self, wrong_name): | ||
try: | ||
has_wrong_name = hasattr(self, wrong_name) | ||
except BaseException: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can swallow things like KeyboardInterrupt and MemoryError. We shouldn't do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then Exception
only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that catch SystemExit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No :)
>>> SystemExit.__mro__
(<class 'SystemExit'>, <class 'BaseException'>, <class 'object'>)
After this change: 2025-04-11.13.45.38.mov |
if hasattr(self, wrong_name): | ||
try: | ||
has_wrong_name = hasattr(self, wrong_name) | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to handle exceptions here? hasattr returns a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because hasattr
triggers __getattr__
which can raise an exception. If it raises - the whole repl process will fail with an error.
It does not cover all side-effects, it will still evaluate
print
, etc.But, it does not fail with exceptions at least.
__getattr__
#132385