`inspect.getmembers_static` triggers `__getattribute__`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
inspect.getmembers_static is documented as not triggering __getattribute__, but it can trigger it via dir. For example the following hits the recursion limit:
class A:
def __getattribute__(self, name: str) -> Any:
getmembers_static(self)
return "all attrs exist!"
A().anything
(A workaround for examples like this one is to add the base cases required by dir to __getattribute__:
if name in ("__dict__", "__class__"):
return object.__getattribute__(self, name)
(The __dict__ case is not always needed depending on the __dir__ implementation.))
Switching getmembers_static to use dir_static (gh-55979) would fix this problem, I believe. getmembers_static already documents that it can't find the dynamically created attributes, etc. that getattr_static can't find, so I don't think such a change would be breaking.
Your environment
- CPython versions tested on: 3.11.0
- Operating system and architecture: Linux-based, x86_64
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從實作 inspect.getmembers_static 以及 gh-55979 中引用的 dir_static 工作開始。重現遞迴範例,然後驗證成員檢查不再透過 dir 觸發 getattribute;當已回報的行為獲得修正,且不變更關於動態建立屬性的文件化限制時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100