-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-116871: Improve name suggestions in tracebacks #116930
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
gh-116871: Improve name suggestions in tracebacks #116930
Conversation
Only include underscored names in name suggestions for AttributeError and ImportError if the original name was underscored.
Lib/traceback.py
Outdated
@@ -1472,12 +1472,16 @@ def _compute_suggestion_error(exc_value, tb, wrong_name): | |||
obj = exc_value.obj | |||
try: | |||
d = dir(obj) | |||
if wrong_name[:1] != '_': |
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.
I guess you're using [:1]
instead of [0]
to handle empty strings. But there are no tests for this.
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.
It seems difficult to create tests for this with the current code.
If write wrong_name[0]
, an IndexError raised for empty wrong_name
will be caught by except Exception
. If write wrong_name[:1]
, then any non-empty names will be filtered out in the code below as too different from empty string. In any case the result is the same -- no suggestions.
Please take a look at the discussion before merging this. I think |
Only include underscored names in name suggestions for AttributeError and ImportError if the original name was underscored.