Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
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'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 |
@devdanzin If you just want to fix the crash, this one-liner does the job: diff --git a/Lib/traceback.py b/Lib/traceback.pyindex 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 |
python-cla-botbot commentedApr 18, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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. |
Uh oh!
There was an error while loading.Please reload this page.
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.