-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30627: Fix error message when keyword arguments are used #2115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1823,6 +1823,9 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |
PyObject *result; | ||
|
||
/* Validate arguments. */ | ||
if (!_PyArg_NoStackKeywords("pack", kwnames)) { | ||
return NULL; | ||
} | ||
soself = (PyStructObject *)self; | ||
assert(PyStruct_Check(self)); | ||
assert(soself->s_codes != NULL); | ||
|
@@ -1832,9 +1835,6 @@ s_pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |
"pack expected %zd items for packing (got %zd)", soself->s_len, nargs); | ||
return NULL; | ||
} | ||
if (!_PyArg_NoStackKeywords("pack", kwnames)) { | ||
return NULL; | ||
} | ||
|
||
/* Allocate a new buffer */ | ||
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 | |
Py_ssize_t offset; | ||
|
||
/* Validate arguments. +1 is for the first arg as buffer. */ | ||
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { | ||
return NULL; | ||
} | ||
soself = (PyStructObject *)self; | ||
assert(PyStruct_Check(self)); | ||
assert(soself->s_codes != NULL); | ||
|
@@ -1886,9 +1889,6 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames | |
} | ||
return NULL; | ||
} | ||
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { | ||
return NULL; | ||
} | ||
|
||
/* Extract a writable memory buffer from the first argument */ | ||
if (!PyArg_Parse(args[0], "w*", &buffer)) | ||
|
@@ -2131,6 +2131,10 @@ pack(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |
PyObject *s_object = NULL; | ||
PyObject *format, *result; | ||
|
||
if (!_PyArg_NoStackKeywords("pack", kwnames)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is needed if we want the Thanks for your feedback! |
||
return NULL; | ||
} | ||
|
||
if (nargs == 0) { | ||
PyErr_SetString(PyExc_TypeError, "missing format argument"); | ||
return NULL; | ||
|
@@ -2159,6 +2163,10 @@ pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |
PyObject *s_object = NULL; | ||
PyObject *format, *result; | ||
|
||
if (!_PyArg_NoStackKeywords("pack_into", kwnames)) { | ||
return NULL; | ||
} | ||
|
||
if (nargs == 0) { | ||
PyErr_SetString(PyExc_TypeError, "missing format argument"); | ||
return NULL; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now
Struct.pack()
just ignores keyword arguments.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I did not know this could be called via a different path. Thanks for spotting this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR, thanks for catching this!