Skip to content

_pyrepl: Mangled input when sys.ps1 is wider than terminal width #159658

Open

Description

@nsyhykui

Bug report

Bug description

In 3.16 (main), if the prompt (sys.ps1) is wider than the terminal width, typing characters results in a mangled line and an unexpected backslash.

Reproducer

  1. Open a narrow terminal:
xterm -geometry 20x10
  1. Start Python 3.16 in it, then set a long prompt:
import sys
sys.ps1 = "a" * 64 + " "
  1. Type Hello.

Actual behavior

The prompt wraps to the next physical line, but _pyrepl seems to miscalculate the layout. It inserts a stray \ and splits the first character from the rest:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa H    \
ello

CPython versions tested on:

3.16

Operating systems tested on:

Linux

Linked PRs

Activity

  1. nsyhykui commented on Oct 18, 2026

    @nsyhykui
    Author

    I found a similar issue on Python 3.14, but it looks much worse. like this:

    >>> import sys
    >>> sys.ps1 = "a" * 128 + " "
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaHelloaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
    
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

    topic-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