[Python-Dev] 'hasattr' is broken by design
Terry Reedy
tjreedy at udel.edu
Mon Aug 23 19:05:51 CEST 2010
On 8/23/2010 10:22 AM, Yury Selivanov wrote:
> 1) I propose to change 'hasattr' behaviour in Python 3, making it to
> swallow only AttributeError exceptions (exactly like 'getattr').
> Probably, Python 3.2 release is our last chance.
I gather that this amounts to changing "an exception" to
"AttributeError" in "(This is implemented by calling getattr(object,
name) and seeing whether it raises an exception or not.)" in both the
doc and implementation, so that the implementation actually matches the
claimed behavior "The result is True if the string is the name of one of
the object’s attributes, False if not. " (and by reasonable implication,
an exception if this cannot be determined).
--
Terry Jan Reedy
More information about the Python-Dev
mailing list