summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_descr.py6
-rw-r--r--Objects/typeobject.c5
2 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index ab55952..872b7ec 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2352,6 +2352,12 @@ def setclass():
pass
else:
raise TestFailed, "shouldn't allow %r.__class__ = %r" % (x, C)
+ try:
+ delattr(x, "__class__")
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "shouldn't allow del %r.__class__" % x
cant(C(), list)
cant(list(), C)
cant(C(), 1)
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index d290278..deb7320 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1605,6 +1605,11 @@ object_set_class(PyObject *self, PyObject *value, void *closure)
PyTypeObject *old = self->ob_type;
PyTypeObject *new, *newbase, *oldbase;
+ if (value == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't delete __class__ attribute");
+ return -1;
+ }
if (!PyType_Check(value)) {
PyErr_Format(PyExc_TypeError,
"__class__ must be set to new-style class, not '%s' object",