Message254722
See this simple example:
class A():
def __init__(self, x=None):
self.x = x
@property
def t(self):
return self.x.t
def __getattr__(self, name):
return 'default'
print(A().t)
AttributeError is raised as "'NoneType' object has no attribute 't'". Currently __getattr__ is called if any AttributeError is raised, so the result of a.t is *default*, while an AttributeError is the desired behavior.
The most intuitive solution seems to add a subclass of AttributeError, say AttributeMissError, which triggers __getattr__. At present, I have to do some tricky and ugly things to __getattribute__ to show where the AttributeError occurs, or it's quite hard to figure out what happened with no informative traceback messages. |
|
Date |
User |
Action |
Args |
2015-11-16 09:39:59 | Jun Wang | set | recipients:
+ Jun Wang |
2015-11-16 09:39:59 | Jun Wang | set | messageid: <1447666799.36.0.119700754928.issue25634@psf.upfronthosting.co.za> |
2015-11-16 09:39:59 | Jun Wang | link | issue25634 messages |
2015-11-16 09:39:58 | Jun Wang | create | |
|