[Grok-dev] Re: Using 'if object' evaluates false - container objects
Philipp von Weitershausen
philipp at weitershausen.de
Fri Apr 13 05:40:32 EDT 2007
Darryl Cousins wrote:
> This mail on zope3-users
> http://mail.zope.org/pipermail/zope3-users/2007-April/006032.html turned
> up just a few days after I found I needed to change a similar statement
> in grok/component.py in Traverser class:
>
> if IReadContainer.providedBy(self.context):
> item = self.context.get(name)
> if item:
> return item
>
> Should 'item' be an empty container it should read:
>
> if item not None:
> return item
>
> Comments?
Yes, just doing "if obj" when you really want to check if it's None is
evil for precisely that reason. I once fixed an occurrence of this bug
in Grok, it seems I missed this one. Feel free to fix this (along with
an ftest).
I also just realized that the Traverser looks up things in the opposite
order than Zope 3 does (first views, then subitems). This should
certainly be fixed (and ftested).
Regarding the XXX comment above the code in question: this *is* normal
Zoep traversal behaviour. Every traversal adapter in Zope3 has to do
these steps.
--
http://worldcookery.com -- Professional Zope documentation and training
More information about the Grok-dev
mailing list