Skip to content

Commit 8ec352a

Browse files
committed
apply petr's comment
1 parent ac19a57 commit 8ec352a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Doc/c-api/type.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ Type Objects
9797
9898
.. c:function:: const char* PyType_GetName(PyTypeObject *type)
9999
100-
Return the type's name.
100+
Return the type's name. The returned pointer includes the module name
101+
if type's name have a prefix of module name.
102+
Callers can hold this pointer until the type has been deallocated.
101103
102104
.. versionadded:: 3.10
103105

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored))
10891089
Py_RETURN_NONE;
10901090
}
10911091
tp_name = PyType_GetName((PyTypeObject *)HeapTypeNameType);
1092-
assert(strcmp(tp_name, "HeapTypeNameType") == 0);
1092+
assert(strcmp(tp_name, "_testcapi.HeapTypeNameType") == 0);
10931093

10941094
Py_DECREF(HeapTypeNameType);
10951095
Py_RETURN_NONE;

Objects/typeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,10 +3157,10 @@ PyType_GetName(PyTypeObject *type)
31573157
{
31583158
assert(PyType_Check(type));
31593159
if (_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
3160-
return PyUnicode_AsUTF8(((PyHeapTypeObject *)type)->ht_name);
3161-
} else {
3162-
return type->tp_name;
3160+
PyTypeObject ht_type = ((PyHeapTypeObject *)type)->ht_type;
3161+
return ht_type.tp_name;
31633162
}
3163+
return type->tp_name;
31643164
}
31653165

31663166
void *

0 commit comments

Comments
 (0)