D
Denis S. Otkidach
I've noticed that the order of attribute lookup is inconsistent
when descriptor is used. property instance takes precedence of
instance attributes:
.... def _get_attr(self):
.... return self._attr
.... attr = property(_get_attr)
....
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in _get_attr
AttributeError: 'A' object has no attribute '_attr'
But it doesn't when I use custom class of descriptor:
.... def __get__(self, inst, cls):
.... return inst._attr
........ attr = descr()
....
Subclasses of property behave like property itself:
.... def __get__(self, inst, cls):
.... return inst._attr
........ attr = descr2()
....
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in __get__
AttributeError: 'C' object has no attribute '_attr'
Is it an undocumented feature or I have to submit a bug report?
when descriptor is used. property instance takes precedence of
instance attributes:
.... def _get_attr(self):
.... return self._attr
.... attr = property(_get_attr)
....
Traceback (most recent call last):a=A()
a.__dict__ {}
a.__dict__['attr']=1
a.__dict__ {'attr': 1}
a.attr
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in _get_attr
AttributeError: 'A' object has no attribute '_attr'
But it doesn't when I use custom class of descriptor:
.... def __get__(self, inst, cls):
.... return inst._attr
........ attr = descr()
....
1b=B()
b.__dict__ {}
b.__dict__['attr']=1
b.__dict__ {'attr': 1}
b.attr
Subclasses of property behave like property itself:
.... def __get__(self, inst, cls):
.... return inst._attr
........ attr = descr2()
....
Traceback (most recent call last):c=C()
c.__dict__ {}
c.__dict__['attr']=1
c.__dict__ {'attr': 1}
c.attr
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in __get__
AttributeError: 'C' object has no attribute '_attr'
Is it an undocumented feature or I have to submit a bug report?