]> granicus.if.org Git - python/commitdiff
Do the check for no keyword arguments in __init__ so that
authorGeorg Brandl <georg@python.org>
Tue, 30 May 2006 08:17:00 +0000 (08:17 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 30 May 2006 08:17:00 +0000 (08:17 +0000)
subclasses of Exception can be supplied keyword args

Lib/test/test_exceptions.py
Objects/exceptions.c

index 20e76b91ba8fbf1fe7914873c11210970ec77d86..6d6adbee8d02510b1e01bd8e65270edcba2284bb 100644 (file)
@@ -299,7 +299,7 @@ for args in exceptionList:
 
 try:
     BaseException(a=1)
-except TypeErrror:
+except TypeError:
     pass
 else:
     raise TestFailed("BaseException shouldn't take keyword args")
index 28fb0c14e88bcc56aaba9adee6d3097c8cbbdb66..fbf10fedab07e5b0744fadf915700ff56cdf4e48 100644 (file)
@@ -32,9 +32,6 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     PyBaseExceptionObject *self;
 
-    if (!_PyArg_NoKeywords("BaseException", kwds))
-        return NULL;
-
     self = (PyBaseExceptionObject *)type->tp_alloc(type, 0);
     /* the dict is created on the fly in PyObject_GenericSetAttr */
     self->message = self->dict = NULL;
@@ -57,6 +54,9 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 static int
 BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
 {
+    if (!_PyArg_NoKeywords(self->ob_type->tp_name, kwds))
+        return -1;
+
     Py_DECREF(self->args);
     self->args = args;
     Py_INCREF(self->args);