Author petr.viktorin
Recipients Alexander.Belopolsky, Arfrever, Robin.Schreiber, amaury.forgeotdarc, belopolsky, jcea, jhaberman, lekma, loewis, petr.viktorin, pitrou
Date 2021-08-02.10:49:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1627901372.37.0.196918054921.issue15870@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2021-08-02 10:49:32petr.viktorinsetrecipients: + petr.viktorin, loewis, jcea, amaury.forgeotdarc, belopolsky, pitrou, Arfrever, lekma, Alexander.Belopolsky, Robin.Schreiber, jhaberman
2021-08-02 10:49:32petr.viktorinsetmessageid: <1627901372.37.0.196918054921.issue15870@roundup.psfhosted.org>
2021-08-02 10:49:32petr.viktorinlinkissue15870 messages
2021-08-02 10:49:32petr.viktorincreate