You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think a useful way to do that would be to have an overridable static_init function that returns the PyDict used to initialize tp_dict, since that also allows non-const code to create the member variables.
The text was updated successfully, but these errors were encountered:
@programmerjake with #905 and #914 is there any more work to be done here? I think we established that the class attributes (as we decided to call them) can't be mutable, so I believe we've covered everything...
I think that should be all that's needed, unless we want to add a function (static_init from first comment) that can add members algorithmically, though that would have to be unsafe since it could save a copy of the dict somewhere and try to modify it after initialization finished.
Let's call this done, as nobody else has asked for more on this front since we added this over a year ago. We can open a new issue if there are real-world use cases for the static_init case.
This can apparently be done by setting
PyTypeObject.tp_dict
to a dict with the appropriate values before callingPyType_Ready
.See https://stackoverflow.com/questions/35954016/defining-an-inner-class-using-the-python-c-api for a use case. Another use case would be creating enum constants (assuming initialization order can be worked out).
I think a useful way to do that would be to have an overridable
static_init
function that returns thePyDict
used to initializetp_dict
, since that also allows non-const code to create the member variables.The text was updated successfully, but these errors were encountered: