Skip to content

Preserve NameError/AttributeError suggestions in traceback formatting#15263

Open
shincho-1000 wants to merge 1 commit into
ipython:mainfrom
shincho-1000:fix-nameerror-suggestions
Open

Preserve NameError/AttributeError suggestions in traceback formatting#15263
shincho-1000 wants to merge 1 commit into
ipython:mainfrom
shincho-1000:fix-nameerror-suggestions

Conversation

@shincho-1000

Copy link
Copy Markdown

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.

@shincho-1000

shincho-1000 commented Jun 15, 2026

Copy link
Copy Markdown
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.

@shincho-1000

shincho-1000 commented Jun 15, 2026

Copy link
Copy Markdown
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NameError/AttributeError suggestions in Python 3.10 error messages

1 participant