Skip to content

REPL: Don't print the line that produced a SyntaxWarning if only a single line was given as input #122396

@AlexWaygood

Description

@AlexWaygood

Feature or enhancement

Bug description:

The old REPL had this behaviour:

~/dev/cpython (main)⚡ % PYTHON_BASIC_REPL=1 ./python.exe
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> False is 0
<stdin>-0:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
False

The new one has this behaviour:

~/dev/cpython (main)⚡ % ./python.exe                             
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0 is False
<python-input-0>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  0 is False
False

The new behaviour seems better if you've given a multiline function as input since, unlike the old REPL, it tells you exactly which line of code produced the warning:

~/dev/cpython (main)⚡ % ./python.exe
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
...     0 is False
...     3 == 4
...     
<python-input-0>:2: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  0 is False

...but it feels a bit redundant if, as in my first example, only a single line was entered as input. It took me a little while to figure out why the REPL was just printing the line I had typed back at me.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-replRelated to the interactive shelltriagedThe issue has been accepted as valid by a triager.type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions