summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-06-29 14:39:29 (GMT)
committerGitHub <noreply@github.com>2021-06-29 14:39:29 (GMT)
commit823460daa9fab3d0cf00ec553d1e35635ef73d40 (patch)
treeb91cfcc6093d29eefdd51670e8ce87265e8de961 /Objects/typeobject.c
parent50148cacfaa79d199b71fec89c2dbe7efbae41ca (diff)
downloadcpython-823460daa9fab3d0cf00ec553d1e35635ef73d40.zip
cpython-823460daa9fab3d0cf00ec553d1e35635ef73d40.tar.gz
cpython-823460daa9fab3d0cf00ec553d1e35635ef73d40.tar.bz2
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.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 3c766e9..8ee4e81 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1065,6 +1065,12 @@ static PyGetSetDef type_getsets[] = {
static PyObject *
type_repr(PyTypeObject *type)
{
+ if (type->tp_name == NULL) {
+ // type_repr() called before the type is fully initialized
+ // by PyType_Ready().
+ return PyUnicode_FromFormat("<class at %p>", type);
+ }
+
PyObject *mod, *name, *rtn;
mod = type_module(type, NULL);