gh-121654: Add PyType_Freeze() function#122457
Conversation
|
Looks sensible to me. |
encukou
left a comment
There was a problem hiding this comment.
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. |
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.
How difficult to add test for this case?
There was a problem hiding this comment.
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. |
Co-authored-by: Petr Viktorin <[email protected]>
| i = 1; | ||
| } | ||
| for (; i<PyTuple_GET_SIZE(bases); i++) { | ||
| PyTypeObject *b = (PyTypeObject*)PyTuple_GET_ITEM(bases, i); |
There was a problem hiding this comment.
Sorry for the necro-posting.
IIUC only improperly constructed tuples can store NULL items. Is this such a case? If so, is the following check redundant?
There was a problem hiding this comment.
I don't know, I just moved the code. The test was already there before.
📚 Documentation preview 📚: https://cpython-previews--122457.org.readthedocs.build/