]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug #541883 (Vincent Fiack).
authorGuido van Rossum <guido@python.org>
Mon, 15 Apr 2002 01:03:30 +0000 (01:03 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 15 Apr 2002 01:03:30 +0000 (01:03 +0000)
A stupid bug in object_set_class(): didn't check for value==NULL
before checking its type.

Bugfix candidate.

Lib/test/test_descr.py
Objects/typeobject.c

index ab5595287c48d3d135745ed730df9bffc6bd901c..872b7ece5d46d0e8470d599f0d46af831a4401de 100644 (file)
@@ -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)
index d2902784a9dc9a46c8ce4eccae1a2c6cdcaf6283..deb73201ebb7c5444b1d7a0c4605f14ac8cb6851 100644 (file)
@@ -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",