Skip to content

gh-143811: Add helpful default error messages to AttributeError and NameError#143813

Closed
johnslavik wants to merge 3 commits intopython:mainfrom
johnslavik:add-default-messages-attributeerror-nameerror
Closed

gh-143811: Add helpful default error messages to AttributeError and NameError#143813
johnslavik wants to merge 3 commits intopython:mainfrom
johnslavik:add-default-messages-attributeerror-nameerror

Conversation

@johnslavik
Copy link
Copy Markdown
Member

@johnslavik johnslavik commented Jan 13, 2026

@johnslavik johnslavik marked this pull request as ready for review January 13, 2026 19:18
Comment thread Lib/traceback.py
Comment on lines 1140 to 1141
wrong_name = getattr(exc_value, "name", None)
if wrong_name is not None and wrong_name in sys.stdlib_module_names:
Copy link
Copy Markdown
Member Author

@johnslavik johnslavik Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope, within the same function: wrong_name = ... and wrong_name is not None and could be removed here.

Copy link
Copy Markdown
Member Author

@johnslavik johnslavik Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka, what do you think? Would it be of benefit to change it in this PR?
I've already made one unrelated change to reduce redundancy (although necessary to keep things simple).

Comment thread Lib/traceback.py
Comment thread Lib/traceback.py Outdated
Co-authored-by: Aaron Wieczorek <aaronw@fastmail.com>
@johnslavik
Copy link
Copy Markdown
Member Author

I'm not confident in this change, but I'll revisit the original issue.

@johnslavik johnslavik closed this Apr 1, 2026
@johnslavik johnslavik deleted the add-default-messages-attributeerror-nameerror branch April 20, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants