diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 500dfc9..c5d20c9 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3031,17 +3031,21 @@ object_set_class(PyObject *self, PyObject *value, void *closure) return -1; } if (!PyType_Check(value)) { - PyErr_Format(PyExc_TypeError, - "__class__ must be set to new-style class, not '%s' object", + PyErr_Format(PyExc_TypeError, "__class__ must be set to a class defined " + "by a class statement, not '%s' object", Py_TYPE(value)->tp_name); return -1; } newto = (PyTypeObject *)value; - if (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) || - !(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)) - { + if(!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE)) { PyErr_Format(PyExc_TypeError, - "__class__ assignment: only for heap types"); + "class__ must be set to a class defined by a class statement, not '%s'", + newto->tp_name); + return -1; + } + if(!(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE)) { + PyErr_SetString(PyExc_TypeError, "__class__ assignment: only for instances " + "of classes defined by class statements"); return -1; } if (compatible_for_assignment(newto, oldto, "__class__")) {