Repository navigation
NameError has different actions when be raised in IDLE #135511
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jun 14, 2025 Locked-chess-official commented
on Jun 14, 2025 ContributorAuthorMore actions- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Jun 14, 2025 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
Reacted by BinFinderI 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
\ns and if present, extract more lines from the output.Locked-chess-official commented
on Jun 15, 2025 ContributorAuthorMore actions- removedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Jan 15, 2026 @Locked-chess-official @shuimu5418 The little images you two posted above took several minutes to appear. If you right-click in the Shell sidebar, you can copy a selection with prompts. Then paste between triple backtick (```) lines.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Sep 26, 2026 - added a commit that references this issue
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone




Bug report
Bug description:
In IDLE, I raised three different exceptions. The output is:
Only
NameErrorcannot 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
NameErrorandAttributeErrorlack of the message in IDLE #135526