python / python/cpython

New REPL: `python -q` outputs unnecessary blank space on empty terminal

Abierto
#131,743 13 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-repl type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:

If I start the new REPL on a clear terminal, I get an unnecessary blank space.

clear; python -q

Image

Whereas this does not happen if I run the old ("basic") REPL:

clear; PYTHON_BASIC_REPL=1 python -q

Image

Analysis

I've tracked this down to these 2 lines of code: https://github.com/python/cpython/blob/3.13/Lib/_pyrepl/unix_console.py#L241-L242

self.__move(0, len(self.screen) - 1)
self.__write("\n")

I don't totally understand this code, but it certainly smells like there's a bug here when dealing with an empty screen (for example, if len(self.screen) == 0, are we trying to move the cursor to index -1?)

I'm not sure what the fix is here, though. I don't really understand this code: why are we moving up to a line just to move the cursor down a line afterwards? why can't we jump straight to where we want to be? I tried digging through the git history for answers, but it looks like this incantation dates back all the way to this initial commit to pypi/pyrepl. I'm not sure how to dig any further back in time.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

I'm using Alacritty, in case that's relevant.

Linked PRs
  • gh-131907

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo el espacio en blanco con clear; python -q y compáralo con PYTHON_BASIC_REPL=1 python -q. Lee Lib/_pyrepl/unix_console.py alrededor de las líneas 241-242, incluidas las llamadas a __move y __write, y revisa el PR enlazado gh-131907. La tarea está terminada cuando la nueva REPL ya no emita el espacio en blanco innecesario en un terminal vacío.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
cli
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.