鉴于:
In [37]: class A:
....: f = 1
....:
In [38]: class B(A):
....: pass
....:
In [39]: getattr(B, 'f')
Out[39]: 1
好的,那要么调用 super 要么爬取 mro?
In [40]: getattr(A, 'f')
Out[40]: 1
这是意料之中的。
In [41]: object.__getattribute__(A, 'f')
Out[41]: 1
In [42]: object.__getattribute__(B, 'f')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-42-de76df798d1d> in <module>()
----> 1 object.__getattribute__(B, 'f')
AttributeError: 'type' object has no attribute 'f'
什么是 getattribute 不做 getattr 做的?
In [43]: type.__getattribute__(B, 'f')
Out[43]: 1
什么?! type.__getattribute__
调用 super 但object
's 版本没有?
In [44]: type.__getattribute__(A, 'f')
Out[44]: 1