Thomas Lotze wrote:
> Jim Fulton <[EMAIL PROTECTED]> wrote:
> 
>> I would change it to just use getattr rather than hasattr.
>>
>> try:
>>     getattr(ob, name)
>> except AttributeError:
>>     return False
>> ...
> 
> This doesn't handle the case that the attribute exists as a property
> but raises an AttributeError when trying to produce its value.

Yes, but this is still better than hasattr() which eats all exceptions. 
I think eating AttributeErrors is fine because to the user of 'ob', it 
would seem that ob.attr wouldn't exist anyway if it threw an 
AttributeError (even if that exception was about something else, it's 
still an AttributeError).

I suggest doing

   marker = object()
   return getattr(ob, name, marker) is marker

rather than

   return hasattr(ob, name)
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to