`inspect.getmembers_static` triggers `__getattribute__`
まだ誰も着手していません。
評価
調査の方向性
inspect.getmembers_static の実装と、gh-55979 で参照されている dir_static の作業から始めてください。再帰の例を再現し、その後、メンバーの検査で dir を介して getattribute が呼び出されなくなったことを確認してください。報告された動作が修正され、動的に作成される属性に関する文書化された制限を変更していなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·