Skip to content

bpo-31229: fix wrong error messages when too many keyword arguments are received#3180

Merged
serhiy-storchaka merged 5 commits into
python:masterfrom
orenmn:bpo31229-fix-err-msgs
Aug 23, 2017
Merged

bpo-31229: fix wrong error messages when too many keyword arguments are received#3180
serhiy-storchaka merged 5 commits into
python:masterfrom
orenmn:bpo31229-fix-err-msgs

Conversation

@orenmn

@orenmn orenmn commented Aug 22, 2017

Copy link
Copy Markdown
Contributor

according to http://bugs.python.org/issue31229, fix the error messages produced when calling the following with too many keyword arguments:

  • itertools.product()
  • ImportError
  • min()
  • max()
  • print()

https://bugs.python.org/issue31229

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just few style nits.

Comment thread Lib/test/test_call.py Outdated

def test_varargs14_kw(self):
msg = r"^product\(\) takes at most 1 keyword argument \(2 given\)$"
self.assertRaisesRegex(TypeError, msg, itertools.product, 0, a=1, b=2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be better to use names of supported arguments (and one unsupported).

Comment thread Lib/test/test_call.py Outdated

def test_varargs17_kw(self):
msg = r"^max\(\) takes at most 2 keyword arguments \(3 given\)$"
self.assertRaisesRegex(TypeError, msg, max, 0, a=1, b=2, c=3)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is enough to test only one of min()/max() functions.

Comment thread Python/getargs.c Outdated
nargs = PyTuple_GET_SIZE(args);
nkwargs = (kwargs == NULL) ? 0 : PyDict_GET_SIZE(kwargs);
if (nargs + nkwargs > len) {
/* adding "keyword" (when nargs == 0) prevents producing wrong error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since the comment is a full sentence, start it by title case letter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants