Petr Viktorin <encu...@gmail.com> added the comment:

> 2. Use eval from C to create the class with a metaclass, eg.
>      class Foo(metaclass=MessageMeta)

You can also call (PyObject_Call*) the metaclass with (name, bases, namespace); 
this should produce a class. Or not:

    >>> class Foo(metaclass=print):
    ...     def foo(self): pass
    ... 
    Foo () {'__module__': '__main__', '__qualname__': 'Foo', 'foo': <function 
Foo.foo at 0x7f6e9ddd9e50>}

PyType_FromSpecEx will surely need to limit the metaclass to subtypes of type. 
What other limitations are there? How closely can we approach the behavior of 
the `class` statement in Python?


> 3. Manually set FooType->ob_type = &MetaType

I wouldn't recommend doing that after PyType_Ready is called. Including 
indirectly, which the type-creation functions in the stable ABI do.

----------
nosy: +petr.viktorin

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue15870>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to