[Zope-Checkins] CVS: Zope3/src/ZODB - Connection.py:1.114.2.1 coptimizations.c:1.26.6.1 serialize.py:1.2.10.1

Jeremy Hylton jeremy at zope.com
Fri Jan 9 15:05:16 EST 2004


On Fri, 2004-01-09 at 15:04, Fred L. Drake, Jr. wrote:
> Jeremy Hylton writes:
>  > I'd prefer you to leave myhasattr() in the code.  I've wasted days of my
>  > life tracking down bugs caused by hasattr()s that swallowed exceptions.
> 
> What gets masked?  It shouldn't be anything but AttributeError.

>>> print hasattr.__doc__
hasattr(object, name) -> bool
 
Return whether the object has an attribute with the given name.
(This is done by calling getattr(object, name) and catching exceptions.)

So if you have a getattr hook and it raises a TypeError, hasattr() will
just return False.  ZODB is full of complicated getattr hooks.  A bug in
one of those ends up being even more baffling if you use hasattr(),
because you never see the exception.

Jeremy





More information about the Zope-Checkins mailing list