python / python/cpython

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

オープン
#131,743 コメント 13 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-repl type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、clear; python -q で空白を再現し、PYTHON_BASIC_REPL=1 python -q と比較します。Lib/_pyrepl/unix_console.py の241-242行付近を読み、__move__write の呼び出しを確認して、リンクされているPR gh-131907を確認します。新しいREPLが空のターミナルで不要な空白を出力しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。