[Zope] ExtensionClass

Michel Pelletier michel@digicool.com
Fri, 24 Sep 1999 15:53:47 -0400


> -----Original Message-----
> From: Howard Shaw [mailto:howard@tyroldata.com]
> Sent: Friday, September 24, 1999 3:07 PM
> To: zope@zope.org
> Subject: [Zope] ExtensionClass
> 

<snip>

> On to the question:
> 
> Is there an equivalent for issubclass and isinstance that will work on
> ExtensionClasses?

A patch has been submitted for this to work with Python 1.6

> I am writing a WxPython/ZODB app that will 
> maintain a tree
> of objects, and dynamically select a class to generate an 
> editable view of
> the object based on its class. These viewer classes attach to object
> classes, such that they can view any given object, or its descendants.
> However, all my classes, to be stored in the ZODB, must subclass from
> Persistence.Persistent, which makes them Extension Class objects from
> Python's perspective, whereupon it refuses to test for inheritance or
> instantiation.

From what I understand, all classes, whether or not they subclass an
ExtensionClass or not, are == <type 'class'>.  If a class object is an
ExtensionClass, it's __class__ == 'ExtensionClass' which is the class of
all extension classes.

So to test for inheritence, you can just ask if 'aClass' is in a
classes' __bases__.  To test for instantiation, you can special case
ExtensionClasses (no need after Python1.6) and sniff for __class__.  If
it doesn't have one, it's a regular python class.  If it does have one,
and it's value is just ExtensionClass, then it's an ExtensionClass.
Otherwise it's an instance.

-Michel