Message249534
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 :) |
|
Date |
User |
Action |
Args |
2015-09-02 10:40:13 | martin.panter | set | recipients:
+ martin.panter, dunric |
2015-09-02 10:40:13 | martin.panter | set | messageid: <1441190413.28.0.486210541762.issue24983@psf.upfronthosting.co.za> |
2015-09-02 10:40:13 | martin.panter | link | issue24983 messages |
2015-09-02 10:40:12 | martin.panter | create | |
|