Preserve NameError/AttributeError suggestions in traceback formatting#15263
Open
shincho-1000 wants to merge 1 commit into
Open
Preserve NameError/AttributeError suggestions in traceback formatting#15263shincho-1000 wants to merge 1 commit into
shincho-1000 wants to merge 1 commit into
Conversation
Author
|
Umm, my own tests are failing for versions 3.11 and 3.13. I'll work on it further. Edit: Actually this only fails for 3.11 and works for 3.13. |
Author
|
While investigating these failures, I found that on Python 3.11 the suggestion text is not present in str(exception), traceback.format_exception(), traceback.print_exception() but it is present when using the built-in sys.excepthook. The current implementation does preserve the message returned by the traceback module, but that is insufficient to reproduce suggestions on 3.11 since it is probably being done by a C-level helper function. I think to implement this we need access to the CPython suggestion logic itself. Is that still in the scope of this issue? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #13445
IPython currently formats exception messages using str(exception), which drops Python's "Did you mean" suggestions for NameError and AttributeError.
This change preserves that suggestion text whenever traceback information is available.
Tests also added for both Verbose and Plain traceback modes.