-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
NameError
has different actions when be raised in IDLE
#135511
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
Comments
3.12 won't get updates as it now only accepts security-only patches but we'll try to fix this in 3.13 and later |
I confirmed that this is IDLE and exception specific. Also, it does not happen if IDLE is started with the -n (no subprocess) option. So it is specific to the exception display in normal mode, which I am sure uses a method in run.py instead of the one in pyshell.py. |
The same error occurs when the raise statement in run from an editor file instead of entered interactively. |
The run.py function print_exception calls nested function print_exc, which prints the lines returned by get_message_lines(typ, exc, tb). The latter special cases AttributeError and NameError to indirectly get the type hint, if available, that is not directly available to Python code. It does this by calling sys.excepthook with stderr temporarily redirected to an io.StringIO. For example: input (NameError, "name 'aab' is not defined.") might result in output "NameError name 'aab' is not defined. Did you mean: 'aaa'?". The returned message is always a single logical line for NameErrors raised by Python itself. The function extracts and return it. This bug would only affect a situation where user code catches a NameError, adds second line to the message, and re-raises a NameError with the 2 (or more) line message. A fix should check the message for embedded |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
In IDLE, I raised three different exceptions. The output is:
Only
NameError
cannot show the Exception Type if the text has two or more lines.In shell the action is same with other exception.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
NameError
andAttributeError
lack of the message in IDLE #135526The text was updated successfully, but these errors were encountered: