As PEP 630 notes, there's no good equivalent for Py*_Check functions (like for PyUnicode_Check for str a static type).
These checks are used to ensure instances have compatible memory layout (and thus, whether it's safe to cast from PyObject to a specific type).
We can assume that types made from the same spec share the memory layout, so, I could imagine API for checking if any superclass was defined using a given PyType_Spec.
This means the API wouldn't be usable without access to that original spec (in particular, it wouldn't be usable with classes created completely "on-demand").
The spec would also need to be stored on the class for this comparison. Since specs for "on-demand" classes can be deallocated right after the class is created, this would become a dangling pointer.
By using the new typechecking API, the user has a pointer to the original spec. Sadly, AFAIK, comparing a live pointer to a dangling pointer is implementation-defined, so we can't use it.
So, there probably needs to be a new flag for saying that the spec will outlive the type (e.g. by being static), which would be required for the type check.
As PEP 630 notes, there's no good equivalent for
Py*_Checkfunctions (like forPyUnicode_Checkforstra static type).These checks are used to ensure instances have compatible memory layout (and thus, whether it's safe to cast from
PyObjectto a specific type).We can assume that types made from the same spec share the memory layout, so, I could imagine API for checking if any superclass was defined using a given PyType_Spec.
This means the API wouldn't be usable without access to that original spec (in particular, it wouldn't be usable with classes created completely "on-demand").
The spec would also need to be stored on the class for this comparison. Since specs for "on-demand" classes can be deallocated right after the class is created, this would become a dangling pointer.
By using the new typechecking API, the user has a pointer to the original spec. Sadly, AFAIK, comparing a live pointer to a dangling pointer is implementation-defined, so we can't use it.
So, there probably needs to be a new flag for saying that the spec will outlive the type (e.g. by being static), which would be required for the type check.