Skip to content

New REPL repeats prompt with newline after each key #127068

Open

Description

@Kurpaph

Bug report

Bug description:

# Add a code block here, if required
>>> input("word\n")
word
word
word
word
word
word
hello
'hello'

When using Python 3.13.0 with the interpreter on Windows Terminal, I tried to write a simple input message to the user with a line break. It resulted in a repetition of the message for every character I wrote and every pressing of a key on the keyboard (including backspace). It does not affect the usability of the input command, but it is annoying.
The bug reproduced on Windows 10 and Windows 11. It does not appear to happen not on the IDLE nor on VSCode.
Windows 11 24H2
Windows 10 22H2

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    type-bug
    on Nov 20, 2024
  2. added
    3.13
    3.14
    topic-repl
    on Nov 20, 2024
  3. terryjreedy commented on Nov 20, 2024

    @terryjreedy
    Member

    Verified not in 3.12, starts in 3.13, so new REPL. Repetition starts with 2nd keypress.

  4. changed the title [-]Input message duplication when adding \n[/-] [+]New REPL repeats prompt with newline after each key[/+] on Nov 20, 2024
  5. shengbo-ma commented on Nov 28, 2024

    @shengbo-ma

    This issue is observed in these OS for me:

    • MacOS: 15.1 (24B83)
    • Linux: Ubuntu 20.04.6 LTS
  6. shengbo-ma commented on Nov 29, 2024

    @shengbo-ma

    This issue looks interesting to me.
    Spent some time digging into it and guess I located where it happens.

    I am willing to fix the issue but lack of context of what the above while loop is supposed to deal with.

    Hope my observation could help whoever will fix this issue.

    TL;DR

    The new reader is not able to calculate the screen when prompt (reader.ps1="word\n") has multiple lines.
    It happens here

    Test Case

    Test case in this post: input("word\n")

    The Code

    Please see the comments on how it happens

                # prompt = "\x1b[1;35mword\n\x1b[0m". following this pattern f"{ANSIColors.BOLD_MAGENTA}{prompt}{ANSIColors.RESET}" It is copied from reader.ps1 which is `word\n`
               # is this while loop supposed to deal with the case when reader.ps1 has multiple lines?
                while "\n" in prompt:
                    pre_prompt, _, prompt = prompt.partition("\n")
                    # pre_prompt = "\x1b[1;35mword"m; prompt = "\x1b[0m"
                    last_refresh_line_end_offsets.append(offset)
                    # bug: screen is wrongly updated: 
                    # Each time user hit a keyboard button, this while loop is executed
                    # the same pre_prompt is added to screen
                    # screen = ["\x1b[1;35mword", "\x1b[1;35mword", "\x1b[1;35mword", ..., "\x1b[0mthe_actual_user_input"]
                    screen.append(pre_prompt)
                    screeninfo.append((0, []))

    I checked the pypy code of pyrepl. This part of code is not modified.

    Tracing the Call

    The calls that the example test case triggers:

  7. StanFromIreland commented on Jan 31, 2025

    @StanFromIreland
    Member

    Does not occur in main branch build in old repl on linux.

    Image

  8. yihong0618 commented on Oct 1, 2025

    @yihong0618
    Contributor

    This bug still exists in main mac

    cc @terryjreedy

    2025-10-01.12.31.25.mov
  9. yihong0618 commented on Oct 1, 2025

    @yihong0618
    Contributor

    Does not occur in main branch build on linux.

    Image

    this only happen in new repl~

  10. added
    stdlib
    3.15
    on Oct 1, 2025
  11. edvilme commented on Aug 7, 2026

    @edvilme
    Contributor

    For me, it is not happening in 3.16 anymore

    3.16 (main)

    Image

    3.13

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.133.143.15stdlibtopic-repltype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions