8000 bpo-44531: Fix type_repr() if tp_name is NULL (GH-26948) · python/cpython@823460d · GitHub
[go: up one dir, main page]

Skip to content

Commit 823460d

Browse files
authored
bpo-44531: Fix type_repr() if tp_name is NULL (GH-26948)
Allow to call type_repr() on a type which is not fully initialized yet. This fix helps debugging crashes occurring early at Python initialization.
1 parent 50148ca commit 823460d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,12 @@ static PyGetSetDef type_getsets[] = {
10651065
static PyObject *
10661066
type_repr(PyTypeObject *type)
10671067
{
1068+
if (type->tp_name == NULL) {
1069+
// type_repr() called before the type is fully initialized
1070+
// by PyType_Ready().
1071+
return PyUnicode_FromFormat("<class at %p>", type);
1072+
}
1073+
10681074
PyObject *mod, *name, *rtn;
10691075

10701076
mod = type_module(type, NULL);

0 commit comments

Comments
 (0)
0