python / python/cpython

`inspect.getmembers_static` triggers `__getattribute__`

オープン
#99,673 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

inspect.getmembers_static の実装と、gh-55979 で参照されている dir_static の作業から始めてください。再帰の例を再現し、その後、メンバーの検査で dir を介して getattribute が呼び出されなくなったことを確認してください。報告された動作が修正され、動的に作成される属性に関する文書化された制限を変更していなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。