[ZODB-Dev] Persistent-derived class instances always callable
Shane Hathaway
shane at zope.com
Fri Oct 17 11:20:00 EDT 2003
John Belmonte wrote:
> With python 2.3.2 and ZODB 3.2c1:
>
> >>> import ZODB
> >>> from Persistence import Persistent
> >>> class Foo(Persistent): pass
> >>> a = Foo()
> >>> callable(a)
> True
>
> What's going on here?
ExtensionClass.Base, a C type, fills the tp_call slot. callable() looks
to see if tp_call is non-null and considers this check to be
authoritative. Although some ExtensionClass instances are callable and
some are not, callable() doesn't go to the effort of discerning the
difference, so it always returns True for ExtensionClass instances.
I think that callable() should only return True if the object has a
__call__ attribute. Now that even functions and methods have __call__
attributes (Python 2.2+), simply checking for the presence of __call__
is actually more reliable than the current callable() implementation.
Shane
More information about the ZODB-Dev
mailing list