New REPL `input` bad cursor position when a backspace char `\b` is in the prompt
Offen
Dieses Issue hat noch niemand übernommen.
stdlib
topic-repl
type-bug
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
Bug description:
New REPL does not position the cursor correctly, if the prompt includes backspace character (\b = \x08)
# Basic REPL shows correct behavior
~$ PYTHON_BASIC_REPL=1 python3
Python 3.15.0a7+ (heads/main:5197ecb, Mar 10 2026, 20:55:52) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> input("Question? _\b")
Question? █
Question? Yes█
'Yes'
>>>
# New REPL misposition the cursor.
~$ python3
Python 3.15.0a7+ (heads/main:5197ecb, Mar 10 2026, 20:55:52) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> input("Question? _\b")
Question? _ █
Question? Yes █
'Yes'
>>>
I've tested code below, and it fixes the issue:
--- ~/.pyenv/versions/3.15-dev/lib/python3.15/_pyrepl/utils.py
+++ ~/.pyenv/versions/3.15-dev/lib/python3.15/_pyrepl/utils.py
@@ -82,7 +82,9 @@
# remove lengths of any escape sequences
sequence = ANSI_ESCAPE_SEQUENCE.findall(s)
ctrl_z_cnt = s.count("\x1a")
- return length - sum(len(i) for i in sequence) + ctrl_z_cnt
+ # remove length of backspaces x 2
+ backspace = s.count("\b")
+ return length - sum(len(i) for i in sequence) + ctrl_z_cnt - 2 * backspace
def unbracket(s: str, including_content: bool = False) -> str:
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Linked PRs
- gh-150488
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Cursorpositionsproblem im neuen REPL mit input("Question? _\b"), und untersuche anschließend _pyrepl/utils.py im Bereich der Berechnung der angezeigten Länge. Vergleiche das Verhalten mit der verlinkten Arbeit in gh-150488; als erledigt gilt die Aufgabe, wenn Prompt und eingegebener Text den Cursor an derselben Position wie das grundlegende REPL lassen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- cli
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100