]> granicus.if.org Git - python/commitdiff
SF bug #963956: Bad error mesage when subclassing a module
authorRaymond Hettinger <python@rcn.com>
Sat, 5 Jun 2004 06:16:22 +0000 (06:16 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 5 Jun 2004 06:16:22 +0000 (06:16 +0000)
Add a more informative message for the common user mistake of subclassing
from a module name rather than another class (i.e. random instead of
random.random).

Python/ceval.c

index 2cebf44a4c971214f7c9e73177aef71dbf35e9b2..2d600141f621e09c8eeaefd6d8fa669b492b756d 100644 (file)
@@ -3922,6 +3922,15 @@ build_class(PyObject *methods, PyObject *bases, PyObject *name)
        }
        result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods);
        Py_DECREF(metaclass);
+       if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
+               /* A type error here likely means that the user passed 
+                  in a base that was not a class (such the random module
+                  instead of the random.random type).  Help them out with
+                  a more informative error message */
+               PyErr_SetString(PyExc_TypeError,
+                       "Error when calling the metaclass.\n" \
+                       "Make sure the base arguments are valid.");
+       }
        return result;
 }