[issue24983] Wrong AttributeError propagation
David Unric
report at bugs.python.org
Wed Sep 2 20:47:09 CEST 2015
David Unric added the comment:
This looks a bit inconsistent. See following version with "manual" getter definition:
class MyClass(object):
def __init__(self, *args, **kwargs):
# setting access to getter by attribute
# without use of property decorator
self.__dict__['myproperty'] = self._myproperty()
def __getattr__(self, name):
print('__getattr__ <<', name)
raise AttributeError(name)
return 'need know the question'
def _myproperty(self):
print(self.missing_attribute)
return 42
my_inst = MyClass()
print(my_inst.myproperty)
# Produces (expected) output
__getattr__ << missing_attribute
Traceback (most recent call last):
File "a.py", line 55, in <module>
my_inst = MyClass()
File "a.py", line 33, in __init__
self.__dict__['myproperty'] = self._myproperty()
File "a.py", line 48, in _myproperty
print(self.missing_attribute)
File "a.py", line 37, in __getattr__
raise AttributeError(name)
AttributeError: missing_attribute
I'd expect the original version using property decorator would behave the same way. Possible issue in property class implementation ?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24983>
_______________________________________
More information about the Python-bugs-list
mailing list