python / python/cpython

Support changing return value of a function in sys.monitoring

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

還沒有人認領這個 Issue。

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

描述

Feature or enhancement

Proposal:

gdb has a command return for users to immediately return from the function. It basically does two things:

  1. stop the execution of the function
  2. return an arbitrary value

In Python, 1. might not be that simple as we have all the references to the stack value (it should be doable, but may or may not worth it), but 2. should be pretty straightforward. We can allow the callback for PY_RETURN function to return something specific (like sys.monitoring.RETURN, retval) to replace the value we are about to return. It should only need to swap the value on the stack and the impact should be contained. Some of the instrumentation structure needs to be refactored a bit but I don't think it's too much work.

With this feature, we can "mock" the return value in the debugger. We can even expand our existing return command - we may not able to return immediately, but we can run until it returns and secretly swap the return value, so we can call this command from anywhere.

Does this sound like a reasonable feature or I'm missing something? @markshannon

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

首先追蹤提案中討論的 sys.monitoring PY_RETURN 回呼和插樁結構。將其與現有的 debugger return 命令進行比較,然後確定如何使用回呼提供的值取代待處理的回傳值。完成的標準是:該行為已完成規格定義、實作,並且已有測試涵蓋函式回傳值的修改。

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

評估

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

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

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