python / python/cpython

REPL: Don't print the line that produced a `SyntaxWarning` if only a single line was given as input

未關閉
#122,396 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-repl triaged type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

Bug description:

The old REPL had this behaviour:

~/dev/cpython (main)⚡ % PYTHON_BASIC_REPL=1 ./python.exe
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> False is 0
<stdin>-0:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
False

The new one has this behaviour:

~/dev/cpython (main)⚡ % ./python.exe                             
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0 is False
<python-input-0>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  0 is False
False

The new behaviour seems better if you've given a multiline function as input since, unlike the old REPL, it tells you exactly which line of code produced the warning:

~/dev/cpython (main)⚡ % ./python.exe
Python 3.14.0a0 (heads/main:4606eff0aa, Jul 23 2024, 20:19:47) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
...     0 is False
...     3 == 4
...     
<python-input-0>:2: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  0 is False

...but it feels a bit redundant if, as in my first example, only a single line was entered as input. It took me a little while to figure out why the REPL was just printing the line I had typed back at me.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先在新的 CPython REPL 中重現單行和多行範例,並比較它們的 SyntaxWarning 輸出。閱讀 REPL 的警告顯示路徑,然後讓單行情況省略回顯的原始碼,同時為多行輸入保留原始碼行;使用有針對性的 REPL 測試驗證這兩種行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。