[Zope-dev] KeywordIndex and PersistentList (Bug?)

Casey Duncan casey@zope.com
Wed, 20 Nov 2002 14:41:50 -0500


Just a note that this can't be put in Zope 2.6 since functions and method=
s=20
don't have a __call__ in Python 2.1.

-Casey

On Wednesday 20 November 2002 02:33 pm, Steve Alexander wrote:
> Thomas Guettler wrote:
>=20
> > Hi!
> >
> > In KeywordIndex the newKeywords get called
> > if they are "callable":
> >     def _get_object_keywords(self,obj):
> >         newKeywords =3D getattr(obj, self.id, ())
> >         if callable(newKeywords):               # (*)
> > =09=09=09newKeywords =3D newKeywords()
> >         if hasattr(newKeywords,'capitalize'): # is it string-like ?
> >             newKeywords =3D (newKeywords, )
> >         return newKeywords
> >
> > This fails if the newKeywords are stored in a PersistentList.
> >
> > Callable is true, but there is no __call__ attribute.
> >
> > I changed the line marked with (*) to
> >  if hasattr(newKeyword, "__call__"):
> >
> > and this seems to work
> >
> > I think this does not break anything and could be included in the
> > original.
> >
> > Am I the first how uses PersistentList for an indexed attribute? Is
> > there a reason not to do so?
>=20
>=20
> The KeywordIndex should be changed to check for the __call__ attribute,=
=20
> rather than relying on 'callable'. You cannot reliably use 'callable'=20
> when you're also using acquisition wrappers.
>=20
> See my comment to this Collector report.
>=20
>    http://collector.zope.org/Zope/578
>=20
> I suggest you report the bug you have found in the Collector.
>=20
> --
> Steve Alexander