Message254928
I think this is a common problem while using both __getattr__ and descriptor/property. A descriptor example:
class Descriptor():
def __get__(self, instance, owner=None):
raise AttributeError('Implicitly suppressed')
class A():
d = Descriptor()
def __getattr__(self, name):
return 'default'
print(A().d)
Without descriptor, unexpected AttributeError could only come from overriding __getattribute__, which is a rare case, although still an imperfection. But in descriptor/property, AttributeError which is too general just occurs frequently like in normal method.
Surely any modification would break the backward compatibility, although I wonder how often it is used of raising AttributeError purposely, maybe in __getattribute__, to call __getattr__, instead of explicitly calling __getattr__. In my understanding this is the only case that will be affected.
"An unexpected exception should not result in subtly altered behaviour, but should cause a noisy and easily-debugged traceback. "—from PEP479
About the implementation, maybe something like "RuntimeError: descriptor raised AttributeError" simulating PEP479. Or in my lay opinion, the best solution is: add object.__getattr__, with the only behavior of raising AttributeError; when normal attribute lookup fails, object.__getattribute__ calls __getattr__ explicitly; __getattr__ not triggered by AttributeError anymore.
I know little about the CPython implementation, so I might be completely wrong. However this seems deserving more detailed discussion. |
|
Date |
User |
Action |
Args |
2015-11-19 19:47:33 | Jun Wang | set | recipients:
+ Jun Wang, r.david.murray |
2015-11-19 19:47:33 | Jun Wang | set | messageid: <1447962453.62.0.824994067342.issue25634@psf.upfronthosting.co.za> |
2015-11-19 19:47:33 | Jun Wang | link | issue25634 messages |
2015-11-19 19:47:33 | Jun Wang | create | |
|