[issue20864] getattr does not work well with descriptor

2014-03-07 Thread Nick Coghlan
Nick Coghlan added the comment: Indeed, since None is a potentially valid attribute value, the required API for a descriptor to indicate "no such attribute" in __get__ is to throw AttributeError. -- nosy: +ncoghlan resolution: -> invalid stage: -> committed/rejected status: open -> c

[issue20864] getattr does not work well with descriptor

2014-03-07 Thread Eric Snow
Eric Snow added the comment: You may get unexpected behavior when you have a descriptor on a class that also has __getattr__ defined. See issue #1615. However, I don't think that applies here. As far as I can tell, everything is working the way it should. -- ___

[issue20864] getattr does not work well with descriptor

2014-03-07 Thread Eric Snow
Eric Snow added the comment: Returning None is the right thing here. The default for getattr() is returned only when it catches an AttributeError (hence the exception is the sentinel, so to speak, not None. Here's a rough equivalent: _notset = object() def getattr(obj, name, default=_no

[issue20864] getattr does not work well with descriptor

2014-03-07 Thread Martin Thurau
New submission from Martin Thurau: If you have a descriptor (in my case it was an SQLAlchemy column) on an instance and this descriptor returns None for a call to __get__ then getattr with a given default value, will not return the default, but None. I have no knowledge on the implementation d