python / python/cpython

Enable error overlays in the REPL

未关闭
#148,228 1 条评论 3 个 reaction 已指派 1 人 在 GitHub 查看

@johnslavik 已经在做这个了。

开始于 2026年4月7日。

stdlib topic-repl type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

Under the trend of improving Python diagnostic messages, I propose we enable the Python REPL error messages (disabled since the PyPy era). There are at least 19 places among various REPL commands where we do log errors, but never display them to the user:

https://github.com/search?q=repo%3Apython%2Fcpython%20%2F(reader%7Cr)%5C.error%2F%20path%3ALib%2F_pyrepl&type=code

I think displaying some of these could be a nice feature.

The best example is:

https://github.com/python/cpython/blob/4f68c046c16cc10ca141b97353e390da03398ed6/Lib/_pyrepl/completing_reader.py#L190-L193

Compare current vs proposed (enabled + colorized):

https://github.com/user-attachments/assets/65f041de-d9c8-4183-8d19-242fa09473a0

Given that we already use overlays for completions, I propose we review errors that we could propagate to the user and open up cool possibilities (we can put "tips" there, we can bundle Levenshtein if tab misses something, if it makes sense). Having this makes it clear when the REPL actually receives keyboard shortcuts but can't do anything with them vs when the keyboard shortcut was incorrect, whereas now it is impossible to distinguish these two states.

https://github.com/user-attachments/assets/a47ee38e-858e-4cb4-afa0-2acc5b8569db

Some of these errors may feel noisy/unclear if the user accidentally presses something, but we can make them easier to understand by attaching context about what key binds were pressed or silencing some errors (e.g. creating .debug() besides .error() and resorting to that one. Then maybe turn this on with an environment variable, etc.).

Feel free to play with the PR to stress-test this.

Digressing a bit, this could turn into something interesting, e.g. we could have a similar overlay for displaying tips with a beautiful 💡 emoji or a "what's new" if we add some new stuff to the REPL. (No, I will never suggest adding LLM snake pets to the REPL. Never.)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-148229

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。