Removing unncessary class states in bdb.Breakpoint
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
According to the comment in the Breakpoint class
Keeping state in the class is a mistake -- this means you cannot have more than one active Bdb instance.
I can support this idea further. Currently, Breakpoint has three class states, next, bplist, and bpbynumber.
class Breakpoint:
...
next = 1
bplist = {}
bpbynumber = [None]
These states are used to enable the reuse of previously set breakpoint instances across multiple interactive sessions or other use cases. However, relying on class states is not the only way to achieve this goal.
Using class states in this case has several clear limitations. As noted in the comment, it makes it difficult to maintain more than one active Bdb instance. Additionally, logic dependent on class state can make the behavior of a new Bdb instance unpredictable in many scenarios unless the exact states of Breakpoint is fully known. Another drawback of maintaining states in the Breakpoint class is that it tightly couples the behavior of all Bdb instances. For example, the deleteMe method must be called periodically by a Bdb instance to ensure the Breakpoint class remains in a valid state.
# example deleteMe calls in Bdb methods
class Bdb:
...
def clear_break(self, filename, lineno):
...
for bp in Breakpoint.bplist[filename, lineno][:]:
bp.deleteMe() # here
self._prune_breaks(filename, lineno)
return None
def clear_bpbynumber(self, arg):
...
try:
bp = self.get_bpbynumber(arg)
except ValueError as err:
return str(err)
bp.deleteMe() # here
self._prune_breaks(bp.file, bp.line)
return None
As an alternative, instance-level state can be maintained within Bdb or derived classes such as Pdb, allowing each instance to manage its own breakpoint data independently. This approach can still support the reuse of previously set breakpoint instances across multiple interactive sessions.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-127410
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/bdb.py 開始,特別查看 Breakpoint 類別以及 issue 中所示的 Bdb 方法,然後檢視連結的 PR gh-127410。確定目前如何在 Bdb 執行個體之間共用中斷點狀態,以及所提議的執行個體層級擁有權將如何影響 Bdb 和 Pdb。完成的標準是:該設計支援彼此獨立的作用中偵錯器執行個體,而不依賴共用的 Breakpoint 類別狀態。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 20/100