.. versionadded:: 3.11
+.. c:function:: PyObject* PyType_GetQualName(PyTypeObject *type)
+
+ Return the type's qualified name. Equivalent to getting the
+ type's ``__qualname__`` attribute.
+
+ .. versionadded:: 3.11
+
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
Return the function pointer stored in the given slot. If the
PyType_GetName:PyObject*::+1:
PyType_GetName:PyTypeObject*:type:0:
+PyType_GetQualName:PyObject*::+1:
+PyType_GetQualName:PyTypeObject*:type:0:
+
PyType_GetSlot:void*:::
PyType_GetSlot:PyTypeObject*:type:0:
PyType_GetSlot:int:slot::
function,PyType_GetModule,3.10,
function,PyType_GetModuleState,3.10,
function,PyType_GetName,3.11,
+function,PyType_GetQualName,3.11,
function,PyType_GetSlot,3.4,
function,PyType_IsSubtype,3.2,
function,PyType_Modified,3.2,
* Add a new :c:func:`PyType_GetName` function to get type's short name.
(Contributed by Hai Shi in :issue:`42035`.)
+* Add a new :c:func:`PyType_GetQualName` function to get type's qualified name.
+ (Contributed by Hai Shi in :issue:`42035`.)
+
New Features
------------
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030B0000
PyAPI_FUNC(PyObject *) PyType_GetName(PyTypeObject *);
+PyAPI_FUNC(PyObject *) PyType_GetQualName(PyTypeObject *);
#endif
/* Generic type check */
--- /dev/null
+Add a new :c:func:`PyType_GetQualName` function to get type's qualified
+name.
function PyType_GetName
added 3.11
+function PyType_GetQualName
+ added 3.11
# (Detailed comments aren't really needed for further entries: from here on
# we can use version control logs.)
}
+static PyObject *
+test_get_type_qualname(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *tp_qualname = PyType_GetQualName(&PyLong_Type);
+ assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "int") == 0);
+ Py_DECREF(tp_qualname);
+
+ tp_qualname = PyType_GetQualName(&_PyNamespace_Type);
+ assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "SimpleNamespace") == 0);
+ Py_DECREF(tp_qualname);
+
+ PyObject *HeapTypeNameType = PyType_FromSpec(&HeapTypeNameType_Spec);
+ if (HeapTypeNameType == NULL) {
+ Py_RETURN_NONE;
+ }
+ tp_qualname = PyType_GetQualName((PyTypeObject *)HeapTypeNameType);
+ assert(strcmp(PyUnicode_AsUTF8(tp_qualname), "HeapTypeNameType") == 0);
+ Py_DECREF(tp_qualname);
+
+ PyObject *spec_name = PyUnicode_FromString(HeapTypeNameType_Spec.name);
+ if (spec_name == NULL) {
+ goto done;
+ }
+ if (PyObject_SetAttrString(HeapTypeNameType,
+ "__qualname__", spec_name) < 0) {
+ Py_DECREF(spec_name);
+ goto done;
+ }
+ tp_qualname = PyType_GetQualName((PyTypeObject *)HeapTypeNameType);
+ assert(strcmp(PyUnicode_AsUTF8(tp_qualname),
+ "_testcapi.HeapTypeNameType") == 0);
+ Py_DECREF(spec_name);
+ Py_DECREF(tp_qualname);
+
+ done:
+ Py_DECREF(HeapTypeNameType);
+ Py_RETURN_NONE;
+}
+
+
static PyObject *
get_args(PyObject *self, PyObject *args)
{
{"get_args", get_args, METH_VARARGS},
{"test_get_statictype_slots", test_get_statictype_slots, METH_NOARGS},
{"test_get_type_name", test_get_type_name, METH_NOARGS},
+ {"test_get_type_qualname", test_get_type_qualname, METH_NOARGS},
{"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs,
METH_VARARGS|METH_KEYWORDS},
{"getargs_tuple", getargs_tuple, METH_VARARGS},
return type_name(type, NULL);
}
+PyObject *
+PyType_GetQualName(PyTypeObject *type)
+{
+ return type_qualname(type, NULL);
+}
+
void *
PyType_GetSlot(PyTypeObject *type, int slot)
{
EXPORT_FUNC(PyType_GetModule)
EXPORT_FUNC(PyType_GetModuleState)
EXPORT_FUNC(PyType_GetName)
+EXPORT_FUNC(PyType_GetQualName)
EXPORT_FUNC(PyType_GetSlot)
EXPORT_FUNC(PyType_IsSubtype)
EXPORT_FUNC(PyType_Modified)