-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions #131001
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-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions #131001
Conversation
I am not convincing this is the right solution. This will hide the real error and as the traceback is missing will make it very difficult to find out what the problem is. The real solution is probably to filter the candidates in the traceback module before submitting it to the @ambv @iritkatriel what do you think? |
I agree with @pablogsal. Either filter in |
Thank you both for the review, sorry for taking so long to address it.
>>> g = {0:1, "p": 1}
>>> exec(compile("pa", 'g', "exec"), g)
[...]
NameError: name 'pa' is not defined
During handling of the above exception, another exception occurred:
[...]
TypeError: all elements in 'candidates' must be strings
[And the REPL exits] So, the current situation in
I suggest we just guard against an exception in the Or we can filter non-strings from the candidates in the |
@devdanzin If you just want to fix the crash, this one-liner does the job: diff --git a/Lib/traceback.py b/Lib/traceback.py
index 647c23ed782..cd5e2a88f07 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -1527,6 +1527,7 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
+ list(frame.f_globals)
+ list(frame.f_builtins)
)
+ d = [name for name in d if isinstance(name, str)]
# Check first if we are in a method and the instance
# has the wrong name as attribute
|
Gentle ping @iritkatriel @pablogsal . Should we go with guarding against the exception and not offering suggestions on |
Non-string keys are legal in dicts. Hints are an excellent by optional (and CPython-specific, I presume) enhancement. The hinters should just ignore, by filtering out, non-string keys and give a hint if possible. There is no reason to not give hint. Hinters are not linters. |
A decision on this (#131001 (comment)) is blocking #130997. If no different opinions are presented, I'm going with @terryjreedy's approach in a day or two. |
I agree with Terry and your final suggestion in the comment, let's filter and provide whatever other suggestions still apply. This is interactive, so unlikely to be "too slow for comfort". |
I've implemented filtering of the candidates, and also guarded against One doubt: when |
@devdanzin What you did is what users will expect 👍🏻 |
Thanks @devdanzin for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
… candidates for suggestions (pythongh-131001) (cherry picked from commit baccfdb) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
GH-135019 is a backport of this pull request to the 3.14 branch. |
… candidates for suggestions (pythongh-131001) (cherry picked from commit baccfdb3d4d004cfb5308674e5e6ea6e598abcd7) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
GH-135020 is a backport of this pull request to the 3.13 branch. |
This PR causes failures when doing refleak hunting. I'm on it. |
The new REPL will exit when given code like:
(See full traceback in #130999 (comment))
With this PR, the repr of the error causing the exit will be displayed instead:
This is an easy, but perhaps too rough, solution. Suggestions for a better way to display the error (or even catch the exception) are very welcome.