]> granicus.if.org Git - python/commitdiff
Tighten the tests for assignment to __bases__: disallow empty tuple.
authorGuido van Rossum <guido@python.org>
Fri, 13 Dec 2002 17:49:38 +0000 (17:49 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 13 Dec 2002 17:49:38 +0000 (17:49 +0000)
Lib/test/test_descr.py
Objects/typeobject.c

index ed4593e8cbede79bde219b21e5f648b54520704b..5a1fcec932c60cb690d70d643f7a4c7d721e973f 100644 (file)
@@ -3485,6 +3485,14 @@ def test_mutable_bases():
     else:
         raise TestFailed, "shouldn't be able to delete .__bases__"
 
+    try:
+        D.__bases__ = ()
+    except TypeError, msg:
+        if str(msg) == "a new-style class can't have only classic bases":
+            raise TestFailed, "wrong error message for .__bases__ = ()"
+    else:
+        raise TestFailed, "shouldn't be able to set .__bases__ to ()"
+
     try:
         D.__bases__ = (D,)
     except TypeError:
index 193b0cc1bc45b832665056cc9454930594cc533c..a9c229af172ae2c4fcea4345d6786f2fe9df4990 100644 (file)
@@ -211,6 +211,12 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
                             type->tp_name, value->ob_type->tp_name);
                return -1;
        }
+       if (PyTuple_GET_SIZE(value) == 0) {
+               PyErr_Format(PyExc_TypeError,
+                    "can only assign non-empty tuple to %s.__bases__, not ()",
+                            type->tp_name);
+               return -1;
+       }
        for (i = 0; i < PyTuple_GET_SIZE(value); i++) {
                ob = PyTuple_GET_ITEM(value, i);
                if (!PyClass_Check(ob) && !PyType_Check(ob)) {