Vitja Makarov, 01.11.2010 08:46:
> I want to see metaclasses in cython.
+1, could you open an enhancement ticket in the bug tracker? I'm surprised
there isn't one yet.
> So I look into the code and I see that classes are generated like this:
>
> class Foo:
> xxx = 111
>
> is transformed in something like:
>
> Foo = Pyx_CreateClass('Foo', bases=(), attrs={})
> # and then it does setattr()
> Foo.xxx = 111
>
> So nothing to do with metaclasses in Pyx_CreateClass() as attributes
> are set after class is actually created ;(
> Btw if class dict will be filled before class creation it's easy to
> handle metaclass stuff in Pyx_CreateClass.
Your description seems to indicate that you want this only for Python
classes, which is fine. I think building the dict before building the class
is the right way to implement this, as the metaclass is allowed to do
whatever it likes with its input, including changes to the class dict. So
it really needs to know the complete dict.
Also see this post:
http://thread.gmane.org/gmane.comp.python.cython.devel/10388
I don't know if the method binding problem has gone away, but it's worth a
try. If it hasn't, it's worth fixing the way methods work, IMHO, but that
may not be low hanging fruit.
The post is from this originating thread, where Ryan Kelly proposed ways to
implement metaclasses:
http://thread.gmane.org/gmane.comp.python.cython.user/1652
I don't think metaclasses for cdef classes are ready to be implemented yet,
but it should be easier for Python classes.
Also note that there is a new syntax for metaclasses in Py3, which I prefer
over the Py2 way. So we will eventually have to support both, although the
Py2 way is easy to emulate for Py3 code.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev