> I propose to break the limited C API backward compatibility on purpose by removing these type definitions form the limited C API.
Hum. How would a C extension subclass the Python int type (PyLong_Type) if it's no longer exposed? One option is to add one function per type, like:
PyObject* Py_GetLongType(void);
It would return a *strong reference* to the type (PyLong_Type).
Another option is to get the type from builtins module or builtins dictionary (PyInterpreterState.builtins). But there is no simple C function to get a builtin object. It requires many calls, handle errors, etc. Maybe a generic helper like the following function would help:
PyObject *Py_GetBuiltin(const char *name);
Note: PyEval_GetBuiltins() exposes the builtins of the *current frame* which maybe not be what you may expect.
Currently, Py_GetBuiltin(name) is not needed since basically *all* Python builtins are *directly* exposed in the C API... |