This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jun Wang
Recipients Jun Wang, r.david.murray
Date 2015-11-19.19:47:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1447962453.62.0.824994067342.issue25634@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-11-19 19:47:33Jun Wangsetrecipients: + Jun Wang, r.david.murray
2015-11-19 19:47:33Jun Wangsetmessageid: <1447962453.62.0.824994067342.issue25634@psf.upfronthosting.co.za>
2015-11-19 19:47:33Jun Wanglinkissue25634 messages
2015-11-19 19:47:33Jun Wangcreate