summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-06-05 06:16:22 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-06-05 06:16:22 (GMT)
commitf2c0830585a4c58c2e0cb6acbfc4efa628563c12 (patch)
tree41fdb4f638ed33aac170a1bc017eb20d08e745a4 /Python
parent0096e262ffe836b4c7511158678f9e257cc3a020 (diff)
downloadcpython-f2c0830585a4c58c2e0cb6acbfc4efa628563c12.zip
cpython-f2c0830585a4c58c2e0cb6acbfc4efa628563c12.tar.gz
cpython-f2c0830585a4c58c2e0cb6acbfc4efa628563c12.tar.bz2
SF bug #963956: Bad error mesage when subclassing a module
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).
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 2cebf44..2d60014 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;
}