Skip to content

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

Merged
merged 3 commits into from
Jun 15, 2017
Merged

bpo-30627: Fix error message when keyword arguments are used #2115

merged 3 commits into from
Jun 15, 2017

Conversation

SylvainDe
Copy link
Contributor

No description provided.

@@ -1832,9 +1832,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)) {
Copy link
Member

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.

Copy link
Contributor Author

@SylvainDe SylvainDe Jun 12, 2017

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.

Copy link
Contributor Author

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!

@@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed if we want the pack (and pack_into) function to have the same behavior as other function, ie checking for (unsupported) keyword arguments is the first check we perform. If we remove it, the tests test_varargs8_kw and test_varargs9_kw fail with error "missing format argument" as the check for keyword happened afterward (in the "s_"-prefixed functions).
I'm happy to get rid of the check and remove/update the test if you think it is better.

Thanks for your feedback!

@serhiy-storchaka serhiy-storchaka merged commit 96c7c06 into python:master Jun 15, 2017
@serhiy-storchaka serhiy-storchaka changed the title bpo-20627: Fix error message when keyword arguments are used bpo-30627: Fix error message when keyword arguments are used Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants