Vitja Makarov, 03.11.2010 22:13: > 2010/11/3 Stefan Behnel: >> I actually don't think that "python3+ handle __metaclass__ itself". Why >> should it? It has syntax support for this very feature. > > Yes, I didnt knew much about python3. > > Now it seems to me that class declaration is more like function call > with special case for metaclass keyword and positional arguments: > > class Base(type): > def __new__(cls, name, bases, attrs, **kwargs): > print(cls, name, bases, attrs, kwargs) > > class Foo(1, 2, 3, metaclass=Base, foo='bar'): > def hello(self): > pass
Yes, I think that's exactly how this should work. Want to give it another try? It seems that the number of positional arguments is fixed, but you can pass any number of keyword arguments, out of which only "metaclass" is special cased and removed (from a copy of the dict, BTW). There is also an additional protocol if the metaclass has a "__prepare__" class method. See "__build_class__". I think the Python 2 protocol in Cython should work as in Py3. Metaclasses in Py2 won't generally support kwargs, but if a user explicitly provides them, it's best to assume that that's intentional. In the worst case, there will be a runtime TypeError. So, kwargs should pass through, except for __metaclass__. If both the __metaclass__ class field and the metaclass kwarg are passed, I'd lean towards ignoring the field and prefer the kwarg, just like Py3 does. It can be argued that this is worth a warning, though. I also think that the parser should extract the metaclass keyword, not the runtime code. So, if provided, it should be passed into __Pyx_CreateClass() as an argument and not in the kwargs. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
