bpo-20627: Fix error message when keyword arguments are used (#2115) · pythoncapi/cpython@96c7c06 · GitHub
Skip to content

Commit 96c7c06

Browse files
SylvainDeserhiy-storchaka
authored andcommitted
bpo-20627: Fix error message when keyword arguments are used (python#2115)
1 parent 8acb4cf commit 96c7c06

4 files changed

Lines changed: 48 additions & 14 deletions

File tree

Lib/test/test_call.py

Lines changed: 26 additions & 0 deletions

Modules/_hashopenssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,11 @@ generate_hash_name_list(void)
931931
Py_buffer view = { 0 }; \
932932
PyObject *ret_obj; \
933933
\
934-
if (!_PyArg_ParseStack(args, nargs, "|O:" #NAME , &data_obj)) { \
934+
if (!_PyArg_NoStackKeywords(#NAME, kwnames)) { \
935935
return NULL; \
936936
} \
937937
\
938-
if (!_PyArg_NoStackKeywords(#NAME, kwnames)) { \
938+
if (!_PyArg_ParseStack(args, nargs, "|O:" #NAME , &data_obj)) { \
939939
return NULL; \
940940
} \
941941
\

Modules/_struct.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,9 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
18231823
PyObject *result;
18241824

18251825
/* Validate arguments. */
1826+
if (!_PyArg_NoStackKeywords("pack", kwnames)) {
1827+
return NULL;
1828+
}
18261829
soself = (PyStructObject *)self;
18271830
assert(PyStruct_Check(self));
18281831
assert(soself->s_codes != NULL);
@@ -1832,9 +1835,6 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
18321835
"pack expected %zd items for packing (got %zd)", soself->s_len, nargs);
18331836
return NULL;
18341837
}
1835-
if (!_PyArg_NoStackKeywords("pack", kwnames)) {
1836-
return NULL;
1837-
}
18381838

18391839
/* Allocate a new buffer */
18401840
result = PyBytes_FromStringAndSize((char *)NULL, soself->s_size);
@@ -1866,6 +1866,9 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
18661866
Py_ssize_t offset;
18671867

18681868
/* Validate arguments. +1 is for the first arg as buffer. */
1869+
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) {
1870+
return NULL;
1871+
}
18691872
soself = (PyStructObject *)self;
18701873
assert(PyStruct_Check(self));
18711874
assert(soself->s_codes != NULL);
@@ -1886,9 +1889,6 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
18861889
}
18871890
return NULL;
18881891
}
1889-
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) {
1890-
return NULL;
1891-
}
18921892

18931893
/* Extract a writable memory buffer from the first argument */
18941894
if (!PyArg_Parse(args[0], "w*", &buffer))
@@ -2131,6 +2131,10 @@ pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
21312131
PyObject *s_object = NULL;
21322132
PyObject *format, *result;
21332133

2134+
if (!_PyArg_NoStackKeywords("pack", kwnames)) {
2135+
return NULL;
2136+
}
2137+
21342138
if (nargs == 0) {
21352139
PyErr_SetString(PyExc_TypeError, "missing format argument");
21362140
return NULL;
@@ -2159,6 +2163,10 @@ pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
21592163
PyObject *s_object = NULL;
21602164
PyObject *format, *result;
21612165

2166+
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) {
2167+
return NULL;
2168+
}
2169+
21622170
if (nargs == 0) {
21632171
PyErr_SetString(PyExc_TypeError, "missing format argument");
21642172
return NULL;

Python/bltinmodule.c

Lines changed: 6 additions & 6 deletions

0 commit comments

Comments
 (0)