@@ -1159,6 +1159,39 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
1159
1159
}
1160
1160
1161
1161
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
+ PyObject * spec_name = PyUnicode_FromString (HeapTypeNameType_Spec .name );
1178
+ if (PyObject_SetAttrString (HeapTypeNameType ,
1179
+ "__qualname__" , spec_name ) < 0 ) {
1180
+ Py_DECREF (spec_name );
1181
+ Py_DECREF (HeapTypeNameType );
1182
+ Py_RETURN_NONE ;
1183
+ }
1184
+ tp_qualname = PyType_GetQualName ((PyTypeObject * )HeapTypeNameType );
1185
+ assert (strcmp (PyUnicode_AsUTF8 (tp_qualname ),
1186
+ "_testcapi.HeapTypeNameType" ) == 0 );
1187
+ Py_DECREF (spec_name );
1188
+ Py_DECREF (tp_qualname );
1189
+
1190
+ Py_DECREF (HeapTypeNameType );
1191
+ Py_RETURN_NONE ;
1192
+ }
1193
+
1194
+
1162
1195
static PyObject *
1163
1196
get_args (PyObject * self , PyObject * args )
1164
1197
{
@@ -5650,6 +5683,7 @@ static PyMethodDef TestMethods[] = {
5650
5683
{"get_args" , get_args , METH_VARARGS },
5651
5684
{"test_get_statictype_slots" , test_get_statictype_slots , METH_NOARGS },
5652
5685
{"test_get_type_name" , test_get_type_name , METH_NOARGS },
5686
+ {"test_get_type_qualname" , test_get_type_qualname , METH_NOARGS },
5653
5687
{"get_kwargs" , (PyCFunction )(void (* )(void ))get_kwargs ,
5654
5688
METH_VARARGS |METH_KEYWORDS },
5655
5689
{"getargs_tuple" , getargs_tuple , METH_VARARGS },
0 commit comments