@@ -1159,6 +1159,46 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
11591159}
11601160
11611161
1162+ static PyObject *
1163+ test_get_type_qualname (PyObject * self , PyObject * Py_UNUSED (ignored ))
1164+ {
1165+ PyObject * tp_qualname = PyType_GetQualName (& PyLong_Type );
1166+ assert (strcmp (PyUnicode_AsUTF8 (tp_qualname ), "int" ) == 0 );
1167+ Py_DECREF (tp_qualname );
1168+
1169+ tp_qualname = PyType_GetQualName (& _PyNamespace_Type );
1170+ assert (strcmp (PyUnicode_AsUTF8 (tp_qualname ), "SimpleNamespace" ) == 0 );
1171+ Py_DECREF (tp_qualname );
1172+
1173+ PyObject * HeapTypeNameType = PyType_FromSpec (& HeapTypeNameType_Spec );
1174+ if (HeapTypeNameType == NULL ) {
1175+ Py_RETURN_NONE ;
1176+ }
1177+ tp_qualname = PyType_GetQualName ((PyTypeObject * )HeapTypeNameType );
1178+ assert (strcmp (PyUnicode_AsUTF8 (tp_qualname ), "HeapTypeNameType" ) == 0 );
1179+ Py_DECREF (tp_qualname );
1180+
1181+ PyObject * spec_name = PyUnicode_FromString (HeapTypeNameType_Spec .name );
1182+ if (spec_name == NULL ) {
1183+ goto done ;
1184+ }
1185+ if (PyObject_SetAttrString (HeapTypeNameType ,
1186+ "__qualname__" , spec_name ) < 0 ) {
1187+ Py_DECREF (spec_name );
1188+ goto done ;
1189+ }
1190+ tp_qualname = PyType_GetQualName ((PyTypeObject * )HeapTypeNameType );
1191+ assert (strcmp (PyUnicode_AsUTF8 (tp_qualname ),
1192+ "_testcapi.HeapTypeNameType" ) == 0 );
1193+ Py_DECREF (spec_name );
1194+ Py_DECREF (tp_qualname );
1195+
1196+ done :
1197+ Py_DECREF (HeapTypeNameType );
1198+ Py_RETURN_NONE ;
1199+ }
1200+
1201+
11621202static PyObject *
11631203get_args (PyObject * self , PyObject * args )
11641204{
@@ -5667,6 +5707,7 @@ static PyMethodDef TestMethods[] = {
56675707 {"get_args" , get_args , METH_VARARGS },
56685708 {"test_get_statictype_slots" , test_get_statictype_slots , METH_NOARGS },
56695709 {"test_get_type_name" , test_get_type_name , METH_NOARGS },
5710+ {"test_get_type_qualname" , test_get_type_qualname , METH_NOARGS },
56705711 {"get_kwargs" , (PyCFunction )(void (* )(void ))get_kwargs ,
56715712 METH_VARARGS |METH_KEYWORDS },
56725713 {"getargs_tuple" , getargs_tuple , METH_VARARGS },
0 commit comments