New REPL `input` bad cursor position when a backspace char `\b` is in the prompt
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema della posizione del cursore nel nuovo REPL con input("Question? _\b"), quindi ispeziona _pyrepl/utils.py intorno al calcolo della lunghezza visualizzata. Confronta il comportamento con il lavoro collegato in gh-150488; il lavoro è completato quando il prompt e il testo digitato lasciano il cursore nella stessa posizione del REPL di base.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- cli
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100