[docs] [issue8722] Documentation for __getattr__

Terry J. Reedy report at bugs.python.org
Sat Aug 7 21:45:20 CEST 2010

Terry J. Reedy <tjreedy at udel.edu> added the comment:

The problem with changing 2.7 docs is that object access is different for old- and new-style properties. Does your example work if you remove 'object'? (IE, can old style classes have properties?)

For new-style classes, the example behavior is clear if you 1. know that object has a .__getattribute__ method inherited by everything when not overriden and 2. read the doc for that which says that __getattr__ is called whenever a __getattribute__ call raises AttributeError, which it does here by passing through the .get error.

For 3.x, I think in 3.3.2. Customizing attribute access,
object.__getattr__(self, name) 
"Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self). name is the attribute name. "

might be replaced by

"Called when self.__getattribute__(name) raise AttributeError because name is not an instance attribute, not found in the class tree for self, or is a property attribute whose .get() method raises AttributeError."

But this does not work for 2.7.

keywords: +patch
nosy: +terry.reedy
stage:  -> needs patch
versions:  -Python 2.6

Python tracker <report at bugs.python.org>

More information about the docs mailing list