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
派生
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. 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 摘要。