[issue45383] PyType_FromSpec API fails to use metaclass of bases
Sebastian Berg
report at bugs.python.org
Fri Dec 17 10:37:58 EST 2021
Sebastian Berg <sebastian at sipsolutions.net> added the comment:
Fully, agree! In the end, `PyType_FromSpec` replaces `type.__new__()` (and init I guess) when working in C. In Python, we would call `type.__new__` (maybe via super) from the `metatype.__new__`, but right now, in C, the metatype cannot reliably use `PyType_FromSpec` in its own `metatype.__new__` to do the same.
I agree with the scenarios:
* If we do not have a custom `metatype.__new__` (init?) then `PyType_FromSpec` should have no reason to refuse doing the work, because nothing can go wrong.
* If we do have a custom `tp_new` the user has to provide C API to create the metaclass instance. But they still need a way to call `type.__new__` in C (i.e. get what `PyType_FromSpec` does, and promising to do the rest).
`PyType_ApplySpec` would provide that way to create a custom `metatype.__new__` in C when `PyType_FromSpec()` would otherwise reject it to make the first scenario safe.
A flag probably can do the same. I have no preference, `ApplySpec` seems great to me.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45383>
_______________________________________
More information about the Python-bugs-list
mailing list