Uh oh!
There was an error while loading. Please reload this page.
gh-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions - #131001
Conversation
pablogsal
commented
Mar 10, 2025
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? |
iritkatriel
commented
Mar 10, 2025
I agree with @pablogsal. Either filter in |
devdanzin
commented
Mar 29, 2025
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'isnotdefinedDuringhandlingoftheaboveexception, anotherexceptionoccurred:
[...]
TypeError: allelementsin'candidates'mustbestrings
[AndtheREPLexits]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 |
tomasr8
commented
Apr 14, 2025
@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
|
devdanzin
commented
May 13, 2025
Gentle ping @iritkatriel@pablogsal . Should we go with guarding against the exception and not offering suggestions on |
terryjreedy
commented
May 13, 2025
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. |
devdanzin
commented
May 29, 2025
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. |
ambv
commented
May 29, 2025
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". |
Uh oh!
There was an error while loading. Please reload this page.
devdanzin
commented
Jun 2, 2025
I've implemented filtering of the candidates, and also guarded against One doubt: when |
ambv
commented
Jun 2, 2025
@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 baccfdb) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
GH-135020 is a backport of this pull request to the 3.13 branch. |
ambv
commented
Jun 2, 2025
This PR causes failures when doing refleak hunting. I'm on it. |
… candidates for suggestions (pythongh-131001)
… candidates for suggestions (pythongh-131001)
… candidates for suggestions (pythongh-131001)
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.