[issue15870] PyType_FromSpec should take metaclass as an argument
Petr Viktorin
report at bugs.python.org
Mon Aug 2 06:49:32 EDT 2021
Petr Viktorin <encukou at 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 <report at bugs.python.org>
<https://bugs.python.org/issue15870>
_______________________________________
More information about the Python-bugs-list
mailing list