[ZODB-Dev] Persistent-derived class instances always callable

John Belmonte jvb at prairienet.org
Fri Oct 17 13:11:38 EDT 2003


Shane Hathaway wrote:
> 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 see.  I take it this problem will go away for Persistent-derived 
classes in a future ZODB since it will stop using extension classes.

> 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.

Checking for __call__ alone doesn't cover class objects.  What is a 
reliable way to determine if an object is a class?  My first stab is:

     str(type(obj)) == "<type 'classobj'>"

but this doesn't cover extension classes for one thing.

-John


-- 
http:// if   le.o  /




More information about the ZODB-Dev mailing list