python / python/cpython

Subtle error in `getattr_hook` example in the Descriptor Guide

Open
#126,090 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open Doc/howto/descriptor.rst around lines 733-740 and compare the getattr_hook example with the implementation behavior described in the issue, especially for class-object attribute lookup. If the discrepancy is confirmed, update the documented return expression and verify that the guide matches the implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.