-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support metaclass parameter in HPyType_FromSpec
#296
Comments
Also xref https://bugs.python.org/issue45383, I think CPython is open to adding API to make this work reasonable without static types (I was confused about Python 3.11 support, I guess there is still some chance we can manage that). |
I've hacked CPython to support metaclasses in
|
I don't think I have any input other than linking that CPython issue :). I hope you can figure it out, but if there is something I may have insight on, let me know. |
Some more notes regarding the issue described in my previous comment: The issue is that:
git with an example using PyType_Ready Practical implication of this is that if one specifies metatype one also has to set |
Support for metatypes in |
Could we add the metaclass to the HPyType_Spec rather than adding it as an extra parameter to HPyType_FromSpec? |
Hi! De-facto maintainer of this API in CPython here. I assume we want our APIs to be similar, if possible. The reason for the argument in CPython is the same as the
Another reason is that CPython's |
Those are two very good reasons. Thanks @encukou! |
This necessary for the numpy port. Numpy defines a metaclass of dtype class, with its own C struct, the gist is:
In order to support this,
HPyType_FromSpec
should take metaclass as an additional parameter. There is even a TODO for this in HPy. The HPy side of things seems to be clear.However, the issue is that
PyType_FromSpecWithBases
does not support metaclasses (https://bugs.python.org/issue15870). I think that we will have to copy the logic ofPyType_FromSpecWithBases
from CPython and delegate back to CPython only at the point where the original code callsPyType_Ready
.The problematic bit is that
PyType_FromSpecWithBases
callsPyType_GenericAlloc(&PyType_Type, nmembers)
, it should calltp_alloc
of the metaclass as suggested in https://bugs.python.org/issue15870.The text was updated successfully, but these errors were encountered: