Martin Panter added the comment:

First of all, I think your a.py line 74 corresponds to the top-level print() 
call. My version of the output:

>>> print(my_inst.myproperty)
__getattr__ << missing_attribute
__getattr__ << myproperty
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in __getattr__
AttributeError: myproperty

This is a bit tricky, but I _think_ this is working as it is meant to. I think 
your central problem is an unhandled AttributeError is leaking:

1. Evaluating “my_inst.myproperty” invokes your myproperty() getter method.

2. That function tries to evaluate “self.missing_attribute”, which invokes your 
__getattr__() method.

3. __getattr__() raises AttributeError for “missing_attribute”.

4. myproperty() does not handle the AttributeError, so it leaks. I’m not sure 
if the documentation is clear on this, but a property getter raising 
AttributeError signals that the property attribute does not exist, even though 
this AttributeError was originally referring to “missing_attribute”.

5. Python thinks that the “myproperty” property doesn’t exist, so it falls back 
to __getattr__().

6. __getattr__() raises AttributeError for “myproperty”.

Hopefully that makes sense and you can see it is working somewhat sensibly :)

----------
nosy: +martin.panter
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24983>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to