[issue8722] Documentation for __getattr__

Terry J. Reedy report at bugs.python.org
Fri Dec 8 21:27:28 EST 2017


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

Before testing, let alone documenting, the status quo, I would like to be sure that suppressing the exception is truly the intended behavior.  Is there a way to get an annotated listing from git (given which patch, and therefore which person, is responsible for each line)?  I will try asking on pydev.

Calling __getattr__ on property failure is a behavior of __getattribute__, not of the property, and I would expect object.__getattribute__ to be tested wherever object is, but I have not found such tests.  If we do add a test, the best model in test_desc.py looks like `def test_module_subclasses(self):`.  The test class would only need __getattr__ and the faulty property.

class Foo(object):
    def __getattr__(self, name):
        print(f'Getattr {name}')
        return True
    @property
    def bing(self):
        print('Property bing')
        raise AttributeError("blarg")

f = Foo()
print(f.bing)

#prints (which would be the log list in a test)
Property bing
Getattr bing
True

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue8722>
_______________________________________


More information about the Python-bugs-list mailing list