[issue42035] [C API] PyType_GetSlot cannot get tp_name

fancitron report at bugs.python.org
Thu Oct 22 09:22:12 EDT 2020


fancitron <fancitron at gmail.com> added the comment:

True enough.  Btw, PyType_FromSpec accepts Py_tp_doc (char *), Py_tp_base (PyTypeObject *), etc ... so to be strictly standard compliant, a union would be necessary.

PyType_GetName() sounds great.

One "proper" workaround at the moment is PyObject_GetAttrString(Py_TYPE(x), "__name__") and then process the result.  This is somewhat "heavy" and strips the module name.  "Py_tp_name" provides a convenient, exception safe, and backward compatible way to access tp_name.

What I actually do right now is to access the (opaque) PyTypeObject::tp_name by pointer offset.  This certain defies the purpose of stable ABI!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42035>
_______________________________________


More information about the Python-bugs-list mailing list