python / python/cpython

PyREPL bracketed paste issue

未關閉
#156,186 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

Bug report

Bug description:

As expected, when sending code to the REPL within bracketed paste, newlines are always interpreted as actual new lines and not as block execution.
But newlines sent just after closing the bracketed paste are interpreted also as newline in Python 3.14, while they should be interpreted as block execution.
If a small delay is added between closing the bracketed paste and sending the newline, the newline is actually interpreted as block execution.

Originally encountered with Neovim's chansend while sending a block of code to a REPL to execute it, but reproduced below in Python:

import os
import pty
import time
import signal

# Start a REPL
pid, fd = pty.fork()
if pid == 0:
    os.execlp("python", "python")
time.sleep(1)

# Send bracketed code and then newline
os.write(fd, b"\x1b[200~print('Help! I need somebody')\nhelp()\n\x1b[201~")
# time.sleep(0.01)
os.write(fd, b"\n")

# Display output
time.sleep(1)
data = os.read(fd, 4096)
os.kill(pid, signal.SIGTERM)
print(data)

On Python <=3.12, the script errors because bracketed paste is not supported.
On Python 3.13, the help is displayed as expected.
On Python 3.14 and 3.15, it ends up with a line continuation ...: and does not show the content of help(), unless there is a time.sleep between sending the bracketed code and the newline.

When sending to bash, the newlines after the closing of the paste are always interpreted as block execution.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-157270

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

首先使用 Python 3.14 執行提供的 pty 重現,並將其行為與 Python 3.13 進行比較。調查 CPython 的 REPL 對 bracketed paste 的處理,以及在結束序列之後立即傳送的 newline;完成的標準是該 newline 無需延遲即可執行貼上的區塊,且該行為由 regression test 涵蓋。

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

評估

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

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

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