-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-121654: Add PyType_Freeze() function #122457
Conversation
Looks sensible to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll take me some time to review this in depth, unfortunately.
Here are some initial thoughts for what I'd want to check.
@encukou: Please review my updated PR. I modified my PR to check I also rebased the PR on the main branch to fix some merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
I have a few suggestions, and the C API WG should vote on new stable API, but I hope those are just formalities.
Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
I created capi-workgroup/decisions#40 |
@zooba: I added to the doc:
Is it what you expected? |
@encukou @serhiy-storchaka: Would you mind to review my PyType_Freeze() implementation? |
@encukou @serhiy-storchaka @erlend-aasland @zooba: Would you mind to review this PR? The API was approved by the C API Working Group. |
if (!PyTuple_Check(mro)) { | ||
Py_DECREF(mro); | ||
PyErr_SetString(PyExc_TypeError, "unable to get the type MRO"); | ||
return -1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How difficult to add test for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that it's possible to create a type with a MRO which is not a tuple. Using a metaclass, it's possible to override the MRO, but internally, Python converts mro()
result into a tuple.
I added this check since type_get_mro()
returns None
if type->tp_mro
is NULL
. But I have no idea how to create a type with type->tp_mro=NULL
. It's more a sanity check.
Merged. Thanks for reviews. |
Thanks Victor. I'll look at using this after the next CPython release |
I mean technically you can use it now if you manually build the main branch. |
📚 Documentation preview 📚: https://cpython-previews--122457.org.readthedocs.build/