python / python/cpython

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

Open
#122,396 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-repl triaged type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the single-line and multiline examples in the new CPython REPL and compare their SyntaxWarning output. Read the REPL warning-display path, then make the single-line case omit the echoed source while preserving the source line for multiline input; verify both behaviors with focused REPL tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.