python / python/cpython

Subtle error in `getattr_hook` example in the Descriptor Guide

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

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

docs
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Documentation

The example below, from the Descriptor Guide, does not seem to reflect the behaviour of the actual implementation.

https://github.com/python/cpython/blob/ced2691de4c9500ac9a5ccded00741a5fc2d9d2c/Doc/howto/descriptor.rst?plain=1#L733-L740

Unless I'm mistaken, line 736 return obj.__getattribute__(name) should actually read return type(obj).__getattribute__(obj, name).

It's easy to miss when thinking of class instances, but the issue becomes more evident when the example is applied to an attribute lookup on a class object instead. The example would call the __getattribute__ method of the class itself, while the actual implementation calls __getattribute__ on the metaclass (not to mention that in this case the call in the example would fail, due to a missing argument, as it is calling a plain function, rather than a bound method).

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

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

はじめの一歩

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

調査の方向性

Doc/howto/descriptor.rst の 733-740 行付近を開き、getattr_hook の例を issue に記載されている実装の動作と比較してください。特にクラスオブジェクトの属性検索を確認してください。相違が確認された場合は、文書化されている return 式を更新し、ガイドが実装と一致していることを検証してください。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

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

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