[Interface-dev] Advisor Metaclasses and Alternate Pythons (including Py3)

Žiga Seilnacht ziga.seilnacht at gmail.com
Tue Mar 31 20:58:06 EDT 2009

glyph at divmod.com wrote:
> The way implements() works right now is to use an advisor metaclass.
> Unfortunately, advisor metaclasses don't work on py3k, and *can't* work 
> unless something changes, since class construction works differently (it 
> doesn't use the dict's __metaclass__ key any more).
> Stack-walking to implement the implements() declaration is also 
> problematic on alternate Python implementations, especially ironpython.
> I'd like to start working on a branch to eliminate the need for advisor 
> metaclasses in ZI itself.  I have a few different ideas about how 
> implements() might be made to work without _getframe, but I'm not sure 
> which owe would be best.

FWIW, I had the attached module in my hack dir for quite some time. It
allows you to specify various class declarations in the bases of the
class definition:

     class IFoo(Interface):

     class Foo(declare.implements(IFoo)):

Unfortunately, the syntax for base classes and metaclasses also had to
be changed:

     class Bar(declare.bases(object).metaclass(type)):

but the changed syntax is more portable than the __metaclass__ syntax,
it works on Python 3.0.

The module itself doesn't use sys._getframe, but it still doesn't work
on IronPython, due to some strange bug in IronPython:

     Traceback (most recent call last):
     TypeError: expected dict, got LocalsDictionary

The module also provides support for class decorators:

     class Baz(declare.decorators(decoratorA, decoratorB)):

Feel free to use any part that you find useful.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: syntose.py
Url: http://mail.zope.org/pipermail/interface-dev/attachments/20090401/3c6c89cf/attachment.pl 

More information about the Interface-dev mailing list