]> granicus.if.org Git - python/commitdiff
bpo-30878: Fix error message when keyword arguments are passed (#2635)
authorSylvain <sylvain.desodt+github@gmail.com>
Sun, 9 Jul 2017 03:45:06 +0000 (05:45 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 9 Jul 2017 03:45:06 +0000 (06:45 +0300)
to staticmethod() and classmethod().

Lib/test/test_call.py
Objects/funcobject.c

index ca678b9deb7250f71436f8337b25f92cebd52fd8..b004b5803c30bf6e6f8e61bed497560610eaec85 100644 (file)
@@ -186,6 +186,14 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
         msg = r"^pack\(\) takes no keyword arguments$"
         self.assertRaisesRegex(TypeError, msg, struct.Struct.pack, struct.Struct(""), x=2)
 
+    def test_varargs12_kw(self):
+        msg = r"^staticmethod\(\) takes no keyword arguments$"
+        self.assertRaisesRegex(TypeError, msg, staticmethod, func=id)
+
+    def test_varargs13_kw(self):
+        msg = r"^classmethod\(\) takes no keyword arguments$"
+        self.assertRaisesRegex(TypeError, msg, classmethod, func=id)
+
     def test_oldargs0_1(self):
         msg = r"keys\(\) takes no arguments \(1 given\)"
         self.assertRaisesRegex(TypeError, msg, {}.keys, 0)
index 841000152f79a671d64c9d1135776f35945d1ef0..e440258d7de542fd2255727819eb67e94ca61590 100644 (file)
@@ -702,10 +702,10 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
     classmethod *cm = (classmethod *)self;
     PyObject *callable;
 
-    if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
-        return -1;
     if (!_PyArg_NoKeywords("classmethod", kwds))
         return -1;
+    if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
+        return -1;
     Py_INCREF(callable);
     cm->cm_callable = callable;
     return 0;
@@ -883,10 +883,10 @@ sm_init(PyObject *self, PyObject *args, PyObject *kwds)
     staticmethod *sm = (staticmethod *)self;
     PyObject *callable;
 
-    if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
-        return -1;
     if (!_PyArg_NoKeywords("staticmethod", kwds))
         return -1;
+    if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
+        return -1;
     Py_INCREF(callable);
     sm->sm_callable = callable;
     return 0;