comparison Python/ceval.c @ 32247:a98f50e50bef legacy-trunk

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).
author Raymond Hettinger <python@rcn.com>
date Sat, 05 Jun 2004 06:16:22 +0000
parents 8ee5a56b8031
children 41c59d80bbc5
comparison
equal deleted inserted replaced
32246:70cfe065eac5 32247:a98f50e50bef
3920 metaclass = (PyObject *) &PyClass_Type; 3920 metaclass = (PyObject *) &PyClass_Type;
3921 Py_INCREF(metaclass); 3921 Py_INCREF(metaclass);
3922 } 3922 }
3923 result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods); 3923 result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods);
3924 Py_DECREF(metaclass); 3924 Py_DECREF(metaclass);
3925 if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError)) {
3926 /* A type error here likely means that the user passed
3927 in a base that was not a class (such the random module
3928 instead of the random.random type). Help them out with
3929 a more informative error message */
3930 PyErr_SetString(PyExc_TypeError,
3931 "Error when calling the metaclass.\n" \
3932 "Make sure the base arguments are valid.");
3933 }
3925 return result; 3934 return result;
3926 } 3935 }
3927 3936
3928 static int 3937 static int
3929 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, 3938 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,