Line-wrapped syntax highlighting in Python shell spills over into program output #152068
Copy link
Copy link
Closed
Closed
Copy link
Labels
OS-macstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
As shown here, when I make the input long enough that the range gets wrapped with a backtick, all subsequent lines until the next command prompt become the same cyan as the text of range.

Tangentially, is there any way to have Python itself stop doing this when the VScode terminal already did it for me in a way I find preferable (since it doesn't insert line-breaks into long one-liners copied from the shell)?
issue 140334 is similar, but this affects the shell, not just IDLE.
CPython versions tested on:
3.14
Operating systems tested on:
macOS, in both VScode and the terminal.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
OS-macstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
StanFromIreland commentedon Jun 24, 2026
I'm struggling to reproduce this issue:
edvilme commentedon Jun 24, 2026
This seems to me like an ANSI issue. Is this with the default Terminal.app or some other?
Edit: It appears the code explicitly singles out Terminal.app
cpython/Lib/_pyrepl/unix_console.py
Lines 215 to 218 in 6c3da17
and overrides the line wrapping
cpython/Lib/_pyrepl/unix_console.py
Lines 493 to 496 in 6c3da17
which could be causing the bug of the reset ANSI escape code not being appended properly to the second line.
edvilme commentedon Jun 25, 2026
I was also struggling to replicate the issue. If the cursor jumps to the new line as you are typing, the ANSI escape sequence is added correctly. If you modify the inside, causing a keyword (not at cursor position) to be split, then the error occurs.
StanFromIreland commentedon Jun 25, 2026
Thanks for the information. I'm not on a mac however, so I can't reproduce it anyway.
edvilme commentedon Jun 25, 2026
Ah that's right I forgot haha. It is a flaky use case but tried the fix and seems to work :)
Merge branch 'main' into pythongh-152068-pyrepl-color-bug
pythongh-152068: Test ANSI reset is emitted on console finish() and r…
gh-152068: Reset PyREPL Colors on prompt finish (#152108)
[3.15] gh-152068: Reset PyREPL Colors on prompt finish (GH-152108) (#…
pythongh-152068: Reset PyREPL Colors on prompt finish (python#152108)
Merge branch '3.14' into backport-pythongh-152068-pyrepl-color-bug
[3.14] gh-152068: Reset PyREPL Colors on prompt finish (GH-152108) (#…