python / python/cpython

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

未關閉
#131,743 13 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-repl type-bug
主要語言
Python
星號
77.2k
分支
36k
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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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 摘要。