Skip to content

"raise SyntaxError(NotImplemented)" exits REPL and IDLE subprocess #152490

Description

@SheepGoatbaa

Bug report

Bug description:

Since Python 3.14, using NotImplemented in a boolean context started to raise TypeError.
Due to this change, raising SyntaxError (or its subclasses) with argument NotImplemented causes TypeError exception chaining and forces restarting the IDLE Shell. It's not reproducible for other exception types.

MRE:

raise SyntaxError(NotImplemented)

Traceback:

Traceback (most recent call last):
  File "C:/Users/benja/AppData/Local/Programs/Python/Python314/example.py", line 1, in <module>
    raise SyntaxError(NotImplemented)
Traceback (most recent call last):
  File "C:/Users/benja/AppData/Local/Programs/Python/Python314/example.py", line 1, in <module>
    raise SyntaxError(NotImplemented)
Traceback (most recent call last):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 590, in runcode
    exec(code, self.locals)
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "C:/Users/benja/AppData/Local/Programs/Python/Python314/example.py", line 1, in <module>
    raise SyntaxError(NotImplemented)
Traceback (most recent call last):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 590, in runcode
    exec(code, self.locals)
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "C:/Users/benja/AppData/Local/Programs/Python/Python314/example.py", line 1, in <module>
    raise SyntaxError(NotImplemented)
Traceback (most recent call last):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 590, in runcode
    exec(code, self.locals)
  File "C:/Users/benja/AppData/Local/Programs/Python/Python314/example.py", line 1, in <module>
    raise SyntaxError(NotImplemented)
  File "<string>", line 0
SyntaxError: NotImplemented

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 172, in main
    ret = method(*args, **kwargs)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 604, in runcode
    print_exception()
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 278, in print_exception
    print_exc(typ, val, tb)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 274, in print_exc
    lines = get_message_lines(typ, exc, tb)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 240, in get_message_lines
    return traceback.format_exception_only(typ, exc)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 181, in format_exception_only
    return list(te.format_exception_only(show_group=show_group, colorize=colorize))
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1263, in format_exception_only
    yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1456, in _format_syntax_error
    msg = self.msg or "<no detail available>"
TypeError: NotImplemented should not be used in a boolean context

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 186, in main
    print_exception()
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 278, in print_exception
    print_exc(typ, val, tb)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 264, in print_exc
    print_exc(type(context), context, context.__traceback__)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 274, in print_exc
    lines = get_message_lines(typ, exc, tb)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 240, in get_message_lines
    return traceback.format_exception_only(typ, exc)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 181, in format_exception_only
    return list(te.format_exception_only(show_group=show_group, colorize=colorize))
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1263, in format_exception_only
    yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1456, in _format_syntax_error
    msg = self.msg or "<no detail available>"
TypeError: NotImplemented should not be used in a boolean context

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\idlelib\run.py", line 190, in main
    traceback.print_exception(type, value, tb, file=sys.__stderr__)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 134, in print_exception
    te.print(file=file, chain=chain, colorize=colorize)
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1573, in print
    for line in self.format(chain=chain, colorize=colorize):
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1510, in format
    yield from _ctx.emit(exc.format_exception_only(colorize=colorize))
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 999, in emit
    for text in text_gen:
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1263, in format_exception_only
    yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
  File "C:\Users\benja\AppData\Local\Programs\Python\Python314\Lib\traceback.py", line 1456, in _format_syntax_error
    msg = self.msg or "<no detail available>"
TypeError: NotImplemented should not be used in a boolean context

================================ RESTART: Shell ================================

So, I suggest changing the part of traceback.py code,

msg = self.msg or "<no detail available>"

to like this:

if self.msg is None:
    msg = "<no detail available>"
else:
    msg = self.msg

CPython versions tested on:

3.14, 3.15

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    and removed on Jun 28, 2026
  2. self-assigned this
    on Jun 28, 2026
  3. added this to IDLE Issues and removed this from IDLE Issueson Jun 28, 2026
  4. changed the title [-]raise SyntaxError(NotImplemented) restarts IDLE Shell[/-] [+]"raise SyntaxError(NotImplemented)" exits REPL and IDLE subprocess[/+] on Jun 28, 2026
  5. terryjreedy commented on Jun 28, 2026

    @terryjreedy
    Member

    This is not just an IDLE issue. The 'raise' works in file input mode but not REPL interaction.

    C:\Users\Terry>py -i -c "raise SyntaxError(NotImplemented)"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
        raise SyntaxError(NotImplemented)
    Traceback (most recent call last):raise SyntaxError(NotImplemented
      File "<string>", line 1, in <module>
      File "<string>", line 0
    SyntaxError: NotImplemented  # Worked; a REPL prompt is printed.
    
    >>> raise SyntaxError(NotImplemented)  # Same statement prints the same traceback, but ...
    Traceback (most recent call last):
      File "<python-input-0>", line 1, in <module>
        raise SyntaxError(NotImplemented)
    Traceback (most recent call last):
      File "<python-input-0>", line 1, in <module>
      File "<string>", line 0
    SyntaxError: NotImplemented
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Programs\Python315\Lib\code.py", line 324, in push
        more = self.runsource(source, filename, symbol=_symbol)
      File "C:\Programs\Python315\Lib\_pyrepl\console.py", line 292, in runsource
        result = self.runcode(code)
      File "C:\Programs\Python315\Lib\_pyrepl\console.py", line 239, in runcode
        self.showtraceback()
      File "C:\Programs\Python315\Lib\code.py", line 128, in showtraceback
        self._showtraceback(typ, value, tb.tb_next, "")
      File "C:\Programs\Python315\Lib\code.py", line 144, in _showtraceback
        self._excepthook(typ, value, tb)
      File "C:\Programs\Python315\Lib\_pyrepl\console.py", line 227, in _excepthook
        lines = traceback.format_exception(
      File "C:\Programs\Python315\Lib\traceback.py", line 201, in format_exception
        return list(te.format(chain=chain, colorize=colorize))
      File "C:\Programs\Python315\Lib\traceback.py", line 1657, in format
        yield from _ctx.emit(exc.format_exception_only(colorize=colorize))
      File "C:\Programs\Python315\Lib\traceback.py", line 1089, in emit
        for text in text_gen:
      File "C:\Programs\Python315\Lib\traceback.py", line 1399, in format_exception_only
        yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
      File "C:\Programs\Python315\Lib\traceback.py", line 1603, in _format_syntax_error
        msg = self.msg or "<no detail available>"
    TypeError: NotImplemented should not be used in a boolean context
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Programs\Python315\Lib\_pyrepl\main.py", line 58, in interactive_console
        run_multiline_interactive_console(console)
      File "C:\Programs\Python315\Lib\_pyrepl\simple_interact.py", line 174, in run_multiline_interactive_console
        console.showtraceback()
      File "C:\Programs\Python315\Lib\code.py", line 128, in showtraceback
        self._showtraceback(typ, value, tb.tb_next, "")
      File "C:\Programs\Python315\Lib\code.py", line 144, in _showtraceback
        self._excepthook(typ, value, tb)
      File "C:\Programs\Python315\Lib\_pyrepl\console.py", line 227, in _excepthook
        lines = traceback.format_exception(
      File "C:\Programs\Python315\Lib\traceback.py", line 201, in format_exception
        return list(te.format(chain=chain, colorize=colorize))
      File "C:\Programs\Python315\Lib\traceback.py", line 1657, in format
        yield from _ctx.emit(exc.format_exception_only(colorize=colorize))
      File "C:\Programs\Python315\Lib\traceback.py", line 1089, in emit
        for text in text_gen:
      File "C:\Programs\Python315\Lib\traceback.py", line 1399, in format_exception_only
        yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
      File "C:\Programs\Python315\Lib\traceback.py", line 1603, in _format_syntax_error
        msg = self.msg or "<no detail available>"
    TypeError: NotImplemented should not be used in a boolean context
    
    C:\Users\Terry>  # The REPL looped and unexpectedly exits.
    

    The IDLE execution also exits. IDLE Shell notices this and restarts.

    The exit is at least somewhat specific to SyntaxError. raise Type/Value/Index/RuntimeError(NotImplemented) in IDLE just print the expect traceback. (I don't know why the difference.)

    The existing code is buggy in that raise SyntaxError(0) should just print 0 as the message, just as passing 1 prints 1 as the message. The initial fix is also buggy in that it does not replace ''. An alternate replacement could be "''".
    Both SyntaxError() and SyntaxError(None) result in .msg being None. An alternative to replacing None would be to just print None as the message. In other words, replacing '' with something is the only action really needed.

  6. terryjreedy commented on Oct 19, 2026

    @terryjreedy
    Member

    About the specificity of the failure for SyntaxError, I wrote "I don't know why the difference." Duh. The line is in _format_syntax_error.

    While I still think replacing all falsey values with the string is wrong, it is a different issue. Such an issue needs separate justification and discussion and might have different backports.

  7. terryjreedy commented on Oct 19, 2026

    @terryjreedy
    Member

    This is 3.13 IDLE (REPL is the same except for pseudofile name.)

    raise SyntaxError(NotImplemented)
    Traceback (most recent call last):
      File "<pyshell#2>", line 1, in <module>
        raise SyntaxError(NotImplemented)
    SyntaxError: NotImplemented
    

    I think that this should be the result after the patch. In other words, treat NotImplemented as truthy, and by extension, anything else without a boolean value (IE, that raises). (Note that True is the default.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions