[issue45064] Raising AttributeError in descriptor decorator causing searching attribute in __mro__

Raymond Hettinger report at bugs.python.org
Tue Aug 31 18:46:04 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

To get a better insight into what is going on, see
https://docs.python.org/3/howto/descriptor.html#invocation-from-an-instance
  
The relevant text is, "So if __getattr__() exists, it is called whenever __getattribute__() raises AttributeError (either directly or in one of the descriptor calls)."

If needed, you can bypass the __getattr__ hook by calling object.__getattribute__ directly:

    >>> object.__getattribute__(C(), 'test')
    Traceback (most recent call last):
      File "<pyshell#6>", line 1, in <module>
      object.__getattribute__(c, 'test')
      File "/Users/raymond/Documents/tmp14.py", line 26, in __get__
        raise AttributeError("Python bug?")
    AttributeError: Python bug?

----------
nosy: +rhettinger

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


More information about the Python-bugs-list mailing list