python / python/cpython

Make the capability of getting the source of interactive code public

未關閉
#133,853 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

Feature or enhancement

Proposal:

In #117500, we create a nice mechanism to register and retrieve the source code of an arbitrary code object. It was a bug fix so we want to keep it as private as possible - it was for PyREPL usage only. However, we did put effort into the design so it can be used in a wider range in the future, and now is the future!

We just passed beta freeze so we have enough time to make it a new feature. The code and mechanism is really simple, it's just about documentation (and whether we want to merge some interfaces).

There are two orthogonal areas I want to bring into discussion, for each I have two proposals:

  1. How do we want the interface
    • Keep it as it is, meaning the user needs to explicitly register and retrieve source code from a complete separate pair of interfaces.
    • Combine getlines and _getline_from_code, making code an optional argument to getlines - take the path when the optional code object is passed in.
  2. How public do we want it to be
    • Make it public to all users.
    • Make it public internally so at least inspect and pdb can use it. (we don't document it, but we keep inspect.getsourcelines work)

In either combination, we have the full backwards compatibility - nothing will be broken. It's more about how much maintenance effort we want to put in and how easy we want the user to use the feature.

An obvious example usage is that, if you want to debug some interactive code, either through pdb.run(), or debug command in pdb. You don't have the source code symbols now, even though it's fully available. With this capability, we can make pdb.run() work nicely with string source code.

cc: @pablogsal

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://github.com/python/cpython/pull/117500

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 PR #117500 開始,檢視用於註冊和擷取互動式原始碼的現有機制。比較提議的 getlines/_getline_from_code 介面,並考慮 inspect 和 pdb 會如何使用它們。完成的標準是決定介面和公開性政策、在適當情況下為此功能撰寫文件,並定義 pdb.run() 或除錯行為的預期表現。

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

評估

技術堆疊
python
領域
devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

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

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