Skip to content

_pyrepl: Syntax highlighting gets corrupted after in-line editing operations #159674

Closed as not planned

Description

@nsyhykui

Bug report

Bug description

In 3.16 (main), syntax highlighting breaks (either stale colors or losing colors) when text is inserted or deleted in the middle of the line, instead of being typed sequentially.

Reproducer 1 (Stale color on parenthesis)

  1. Type print() in the REPL.
  2. Press the Left arrow key to move the cursor between ( and ).
  3. Type "Hello".
  4. The final ) is incorrectly highlighted in green.

Reproducer 2 (Losing string color)

  1. Type + "Hello".
  2. Press HOME (move to start of line).
  3. Type "Hello ".
  4. Press LEFT (move cursor left).
  5. Delete a character (e.g., the space).
  6. Press RIGHT.
  7. Type a space.
  8. The second "Hello" and the + sign lose their syntax highlighting and are rendered in default white.

Observation

  • Typing code continuously from left to right renders the colors correctly.
  • The highlighting issues only occur when editing existing text (moving the cursor, inserting, or deleting).

CPython versions tested on:

3.16

Operating systems tested on:

Linux

Activity

  1. lazerg commented on Oct 18, 2026

    @lazerg
    Contributor

    I can't reproduce this on current main (b00a140). I built it on Linux and ran both reproducers in a real xterm with TERM=xterm and TERM=xterm-256color, typing slowly and in fast bursts, and the colors come out right every time: print("Hello") ends with a plain ), and the second one ends as "Hello" + "Hello" with both strings green.

    One thing about reproducer 2: if step 5 uses the Delete key instead of Backspace, it removes the closing quote rather than the space, so the line becomes "Hello + "Hello". The second Hello is then outside a string, so showing it uncolored is correct. Also, + and ) have no color in the default theme, so they should always look like plain text.

    Could you share the output of python -VV, which terminal emulator you use (and its version), and echo $TERM? If it still happens for you, running PYREPL_TRACE=/tmp/pyrepl.log python and attaching that log would show exactly what the REPL redrew on each keystroke.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    pendingThe issue will be closed if no feedback is provided
    on Oct 18, 2026
  3. nsyhykui commented on Oct 18, 2026

    @nsyhykui
    Author

    Thanks for checking! Here is the python -VV output:
    Python 3.16.0a1+dev (heads/main:0fedf78, Oct 18 2026, 08:16:21) [Clang 19.1.7 (3+b1)]

    For Reproducer 2, I double-checked and I actually used the Backspace key (deleting the space), not Delete.

    For both reproducers, I cannot reproduce them in a normal terminal like xterm. They only happen in my specific terminal emulator (Termux on Android).

    So this does not seem to be a CPython bug. I'll close this issue as not planned. Thanks for pointing me to the trace tool and for your help!

    pyrepl.log

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

    pendingThe issue will be closed if no feedback is providedstdlibStandard 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