summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index c35eac7..0a3c6e0 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1160,6 +1160,46 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
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)
{
if (args == NULL) {
@@ -5667,6 +5707,7 @@ static PyMethodDef TestMethods[] = {
{"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},