martin f krafft  <[EMAIL PROTECTED]> wrote:
> also sprach Florent Guillaume <[EMAIL PROTECTED]> [2005.03.24.1814 +0100]:
> > > -        if RESPONSE is not None:
> > > +        if RESPONSE is not None and ob:
> > 
> > You should check 'and ob is not None' too.
> 
> ... but ob is false when it is None, no?

Yes but comparing to None is faster, and in some cases (REQUEST for
instance), much much faster, than checking the boolean value.

> > But why could it be None ? What's the point (sorry I don't have
> > context).
> 
> Well, I was trying to guard against errors made in other parts of
> the code. I know I should not do this. It made things a lot easier
> while I was preparing some other patches. Anyway, good thing
> I haven't committed. :)
> 
> > > +            if not hasattr(ob, 'absolute_url'):
> > 
> > Do not use hasattr for persistent objects. Use
> >                if getattr(ob, 'absolute_url', None) is None:
> 
> Can I read up on the rationale somewhere?

It was discussed at length on the zope lists. Basically hasattr tries to
access the attribute and returns false if *any* exception is raised.
This hides exceptions, which is bad in the case of persistent objects
that can raise ConflictErrors.

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]
_______________________________________________
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