gh-129605: Add more exception handling when computing suggestions in traceback.py #129632
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
_compute_suggestion_error
intraceback.py
, the code that handlesAttributeError
andImportError
is wrapped intry
-except
s, but the code for NameError is not wrapped in atry
-except
. However, thehasattr(self, wrong_name)
call fails if accessing an attribute raises an exception. This is what happens in the reproducer in the issue.I wrapped the handling of
NameError
in a try-except to match the handling of the other two exception types.I also added three related tests to test_traceback.py. All three of the new tests crash both PyREPL and the test_traceback.py test suite without the fix. The property test needed some creativity to trigger the bug and I'm a bit proud of it 😛
Let me know if the tests also need to be added to the PyREPL test suite.
__getattr__
raising #129605