1) If attrname is a special (i.e. Python-provided) attribute for objectname, return it.
(The attribute of Python-provided are something like 'this':
__lolcat__, __doc__, __weakref__ and so on)
2)Check objectname.__class__.__dict__ for attrname.
If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case.
3)Check objectname.__dict__ for attrname, and return if found.
If objectname is a class, search its bases too.
If it is a class and a descriptor exists in it or its bases,
return the descriptor result.
4)Check objectname.__class__.__dict__ for attrname.
If it exists and is a non-data descriptor, return the descriptor result.
If it exists, and is not a descriptor, just return it.
(If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.)
Search all bases of objectname.__class__ for same case.
5)Raise AttributeError.
如果objectname
是实例
:
1)Check objectname.__class__.__dict__
for attrname
.
If it exists and is a data-descriptor
, return the descriptor
result. Search all bases
of objectname.__class__
for the same case.
(在父类,以及父类的基类中查找data-descriptor属性,找到data-descriptor才返回)
2)Check objectname.__dict__
for attrname
, and return if found.
(在实例自身中 查找,只要找到就返回,不管是不是descriptor属性)
3)Check objectname.__class__.__dict__
for attrname
.
似乎还要加上objectname.__class__.__basses__.__dict__
If it exists and is a non-data descriptor
, return the descriptor
result.
If it exists, and is not a descriptor
, just return it.
(If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.)
(在父类中查找non-data descriptor和非descriptor
属性,找到就返回)
如果objectname
是类对象
:
1)Check objectname.__class__.__dict__
for attrname
.
If it exists and is a data-descriptor
, return the descriptor
result. Search all bases
of objectname.__class__
for the same case.
(在父类,以及父类的基类中查找data-descriptor属性,找到data-descriptor才返回)
2)Search objectname.__dict__
and objectname.__bases__
for attrname
. If a descriptor
exists in objectname
or objectname.__bases__
, return the descriptor
result.
(在自身,以及自身的基类中查找descriptor属性,只有找到descriptor属性,才返回)
3)Check objectname.__class__.__dict__
for attrname
.
似乎还要加上objectname.__class__.__basses__.__dict__
If it exists and is a non-data descriptor
, return the descriptor
result.
If it exists, and is not a descriptor
, just return it.
(If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.)
(在父类中查找non-data descriptor和非descriptor
属性,找到就返回)
网友评论