[Zope3-dev] Interface package broken for Python 2.2 metaclasses
Phillip J. Eby
pje@telecommunity.com
Thu, 31 Jan 2002 18:49:17 -0500
I'm not sure where to send/post this. I'm working on porting TransWarp to
use Python 2.2 metaclasses instead of ExtensionClass, and I have found a
problem with the Interface package (which TransWarp makes some pretty heavy
use of).
The problem is that the routines in the Interface.iclass module check
whether a type is in 'ClassTypes' in order to know if an object is a class
(and thus whether '__implements__' or '__class_implements__' should be
used). If you have a class based on a Python metaclass, the Interface
package will think the class implements what its instances implement, which
leads to the collapse of the type system as we know it. :)
Unfortunately, despite some hacking around with it myself, I can't seem to
wrap my brain around a decent solution. I tried registering the metaclass
with 'Interface.assertTypeImplements()', but that didn't help because it
checks the '__implements__' attribute *before* checking the type registry.
(It sort of seems to me that 'assertTypeImplements' may be wrongly named
anyhow, since it actually asserts that *instances* of the type implement
something. But that's entirely beside my point at present...)
Would it perhaps make sense to change ClassTypes to a dictionary, and
supply an 'Interface.declareMetaclass()' call that would add a metaclass to
ClassTypes? This seems messy, but so far I haven't been able to figure out
any better way to intelligently detect that a Python metaclass is a
class-like thing.
I've made a hack equivalent to 'declareMetaClass()' in my own copy of the
Interface package for 2.2, and it solves my problem for now, but what
should be done to the official package? Anyone have any better ideas?