Skip to content

Commit 9648088

Browse files
SylvainDeserhiy-storchaka
authored andcommitted
bpo-30878: Fix error message when keyword arguments are passed (#2635)
to staticmethod() and classmethod().
1 parent aa6a4d6 commit 9648088

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Lib/test/test_call.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ def test_varargs11_kw(self):
186186
msg = r"^pack\(\) takes no keyword arguments$"
187187
self.assertRaisesRegex(TypeError, msg, struct.Struct.pack, struct.Struct(""), x=2)
188188

189+
def test_varargs12_kw(self):
190+
msg = r"^staticmethod\(\) takes no keyword arguments$"
191+
self.assertRaisesRegex(TypeError, msg, staticmethod, func=id)
192+
193+
def test_varargs13_kw(self):
194+
msg = r"^classmethod\(\) takes no keyword arguments$"
195+
self.assertRaisesRegex(TypeError, msg, classmethod, func=id)
196+
189197
def test_oldargs0_1(self):
190198
msg = r"keys\(\) takes no arguments \(1 given\)"
191199
self.assertRaisesRegex(TypeError, msg, {}.keys, 0)

Objects/funcobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
702702
classmethod *cm = (classmethod *)self;
703703
PyObject *callable;
704704

705-
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
706-
return -1;
707705
if (!_PyArg_NoKeywords("classmethod", kwds))
708706
return -1;
707+
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
708+
return -1;
709709
Py_INCREF(callable);
710710
cm->cm_callable = callable;
711711
return 0;
@@ -883,10 +883,10 @@ sm_init(PyObject *self, PyObject *args, PyObject *kwds)
883883
staticmethod *sm = (staticmethod *)self;
884884
PyObject *callable;
885885

886-
if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
887-
return -1;
888886
if (!_PyArg_NoKeywords("staticmethod", kwds))
889887
return -1;
888+
if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
889+
return -1;
890890
Py_INCREF(callable);
891891
sm->sm_callable = callable;
892892
return 0;

0 commit comments

Comments
 (0)