Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bf9075a0
Commit
bf9075a0
authored
Aug 23, 2017
by
Oren Milman
Committed by
Serhiy Storchaka
Aug 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31229: Fixed wrong error messages when too many keyword arguments are received. (#3180)
parent
772d809a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
Lib/test/test_call.py
Lib/test/test_call.py
+21
-0
Python/getargs.c
Python/getargs.c
+8
-2
No files found.
Lib/test/test_call.py
View file @
bf9075a0
...
@@ -7,6 +7,7 @@ except ImportError:
...
@@ -7,6 +7,7 @@ except ImportError:
_testcapi
=
None
_testcapi
=
None
import
struct
import
struct
import
collections
import
collections
import
itertools
# The test cases here cover several paths through the function calling
# The test cases here cover several paths through the function calling
# code. They depend on the METH_XXX flag that is used to define a C
# code. They depend on the METH_XXX flag that is used to define a C
...
@@ -194,6 +195,26 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
...
@@ -194,6 +195,26 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
msg = r"
^
classmethod
\
(
\
)
takes
no
keyword
arguments
$
"
msg = r"
^
classmethod
\
(
\
)
takes
no
keyword
arguments
$
"
self.assertRaisesRegex(TypeError, msg, classmethod, func=id)
self.assertRaisesRegex(TypeError, msg, classmethod, func=id)
def test_varargs14_kw(self):
msg = r"
^
product
\
(
\
)
takes
at
most
1
keyword
argument
\
(
2
given
\
)
$
"
self.assertRaisesRegex(TypeError, msg,
itertools.product, 0, repeat=1, foo=2)
def test_varargs15_kw(self):
msg = r"
^
ImportError
\
(
\
)
takes
at
most
2
keyword
arguments
\
(
3
given
\
)
$
"
self.assertRaisesRegex(TypeError, msg,
ImportError, 0, name=1, path=2, foo=3)
def test_varargs16_kw(self):
msg = r"
^
min
\
(
\
)
takes
at
most
2
keyword
arguments
\
(
3
given
\
)
$
"
self.assertRaisesRegex(TypeError, msg,
min, 0, default=1, key=2, foo=3)
def test_varargs17_kw(self):
msg = r"
^
print
\
(
\
)
takes
at
most
4
keyword
arguments
\
(
5
given
\
)
$
"
self.assertRaisesRegex(TypeError, msg,
print, 0, sep=1, end=2, file=3, flush=4, foo=5)
def test_oldargs0_1(self):
def test_oldargs0_1(self):
msg = r"
keys
\
(
\
)
takes
no
arguments
\
(
1
given
\
)
"
msg = r"
keys
\
(
\
)
takes
no
arguments
\
(
1
given
\
)
"
self.assertRaisesRegex(TypeError, msg, {}.keys, 0)
self.assertRaisesRegex(TypeError, msg, {}.keys, 0)
...
...
Python/getargs.c
View file @
bf9075a0
...
@@ -1654,11 +1654,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
...
@@ -1654,11 +1654,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
nargs
=
PyTuple_GET_SIZE
(
args
);
nargs
=
PyTuple_GET_SIZE
(
args
);
nkwargs
=
(
kwargs
==
NULL
)
?
0
:
PyDict_GET_SIZE
(
kwargs
);
nkwargs
=
(
kwargs
==
NULL
)
?
0
:
PyDict_GET_SIZE
(
kwargs
);
if
(
nargs
+
nkwargs
>
len
)
{
if
(
nargs
+
nkwargs
>
len
)
{
/* Adding "keyword" (when nargs == 0) prevents producing wrong error
messages in some special cases (see bpo-31229). */
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes at most %d argument%s (%zd given)"
,
"%.200s%s takes at most %d
%s
argument%s (%zd given)"
,
(
fname
==
NULL
)
?
"function"
:
fname
,
(
fname
==
NULL
)
?
"function"
:
fname
,
(
fname
==
NULL
)
?
""
:
"()"
,
(
fname
==
NULL
)
?
""
:
"()"
,
len
,
len
,
(
nargs
==
0
)
?
"keyword "
:
""
,
(
len
==
1
)
?
""
:
"s"
,
(
len
==
1
)
?
""
:
"s"
,
nargs
+
nkwargs
);
nargs
+
nkwargs
);
return
cleanreturn
(
0
,
&
freelist
);
return
cleanreturn
(
0
,
&
freelist
);
...
@@ -2077,11 +2080,14 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs,
...
@@ -2077,11 +2080,14 @@ vgetargskeywordsfast_impl(PyObject **args, Py_ssize_t nargs,
nkwargs
=
0
;
nkwargs
=
0
;
}
}
if
(
nargs
+
nkwargs
>
len
)
{
if
(
nargs
+
nkwargs
>
len
)
{
/* Adding "keyword" (when nargs == 0) prevents producing wrong error
messages in some special cases (see bpo-31229). */
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes at most %d argument%s (%zd given)"
,
"%.200s%s takes at most %d
%s
argument%s (%zd given)"
,
(
parser
->
fname
==
NULL
)
?
"function"
:
parser
->
fname
,
(
parser
->
fname
==
NULL
)
?
"function"
:
parser
->
fname
,
(
parser
->
fname
==
NULL
)
?
""
:
"()"
,
(
parser
->
fname
==
NULL
)
?
""
:
"()"
,
len
,
len
,
(
nargs
==
0
)
?
"keyword "
:
""
,
(
len
==
1
)
?
""
:
"s"
,
(
len
==
1
)
?
""
:
"s"
,
nargs
+
nkwargs
);
nargs
+
nkwargs
);
return
cleanreturn
(
0
,
&
freelist
);
return
cleanreturn
(
0
,
&
freelist
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment