diff --git a/Objects/typeobject.c b/Objects/typeobject.c index cc4612f9308..4582dfb6afe 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4083,6 +4083,16 @@ _PyStaticType_Dealloc(PyTypeObject *type) // A subtype can inherit attributes and methods of its parent type, // and a type must no longer be used once it's deallocated. if (type->tp_subclasses != NULL) { + if (type->tp_subclasses != NULL) { + fprintf(stderr, "Cannot deallocate type '%s': it still has subclasses\n", type->tp_name); + Py_ssize_t i = 0; + PyObject *ref; + while (PyDict_Next(type->tp_subclasses, &i, NULL, &ref)) { + PyObject *obj = PyWeakref_GET_OBJECT(ref); + PyTypeObject *subclass = _PyType_CAST(obj); + fprintf(stderr, "* %s\n", subclass->tp_name); + } + } return; }