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
6326278e
Commit
6326278e
authored
Dec 21, 2018
by
Xtreak
Committed by
Serhiy Storchaka
Dec 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34193: Fix pluralization in getargs.c and test cases. (GH-8438)
parent
3e8f962e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
23 deletions
+38
-23
Lib/test/test_call.py
Lib/test/test_call.py
+7
-4
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+4
-4
Misc/NEWS.d/next/C API/2018-07-24-11-57-35.bpo-34193.M6ch1Q.rst
...EWS.d/next/C API/2018-07-24-11-57-35.bpo-34193.M6ch1Q.rst
+2
-0
Objects/typeobject.c
Objects/typeobject.c
+1
-1
Python/getargs.c
Python/getargs.c
+24
-14
No files found.
Lib/test/test_call.py
View file @
6326278e
...
...
@@ -160,19 +160,22 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
msg = r"
^
from_bytes
\
(
\
)
takes
at
most
2
positional
arguments
\
(
3
given
\
)
"
self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False)
def test_varargs
4
(self):
def test_varargs
1min
(self):
msg = r"
get
expected
at
least
1
argument
,
got
0
"
self.assertRaisesRegex(TypeError, msg, {}.get)
def test_varargs5(self):
msg = r"
expected
1
argument
,
got
0
"
self.assertRaisesRegex(TypeError, msg, {}.__delattr__)
def test_varargs2min(self):
msg = r"
getattr
expected
at
least
2
arguments
,
got
0
"
self.assertRaisesRegex(TypeError, msg, getattr)
def test_varargs
6
(self):
def test_varargs
1max
(self):
msg = r"
input
expected
at
most
1
argument
,
got
2
"
self.assertRaisesRegex(TypeError, msg, input, 1, 2)
def test_varargs
7
(self):
def test_varargs
2max
(self):
msg = r"
get
expected
at
most
2
arguments
,
got
3
"
self.assertRaisesRegex(TypeError, msg, {}.get, 1, 2, 3)
...
...
Lib/test/test_getargs2.py
View file @
6326278e
...
...
@@ -682,11 +682,11 @@ class PositionalOnlyAndKeywords_TestCase(unittest.TestCase):
self.assertEqual(self.getargs(1), (1, -1, -1))
# required positional arg missing
with self.assertRaisesRegex(TypeError,
r"
function
takes
at
least
1
positional
argument
s
\
(
0
given
\
)
"):
r"
function
takes
at
least
1
positional
argument
\
(
0
given
\
)
"):
self.getargs()
with self.assertRaisesRegex(TypeError,
r"
function
takes
at
least
1
positional
argument
s
\
(
0
given
\
)
"):
r"
function
takes
at
least
1
positional
argument
\
(
0
given
\
)
"):
self.getargs(keyword=3)
def test_empty_keyword(self):
...
...
@@ -1112,7 +1112,7 @@ class ParseTupleAndKeywords_Test(unittest.TestCase):
parse((1,), {'a': 3}, 'OOO', ['', '', 'a'])
parse((1,), {}, 'O|OO', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
r'function takes at least 1 positional argument
s
\
(
0
given
\
)
'
):
r'function takes at least 1 positional argument
\
(
0
given
\
)
'
):
parse((), {}, 'O|OO', ['', '', 'a'])
parse((1, 2), {'a': 3}, 'OO$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
...
...
@@ -1120,7 +1120,7 @@ class ParseTupleAndKeywords_Test(unittest.TestCase):
parse((1,), {'a': 3}, 'OO$O', ['', '', 'a'])
parse((1,), {}, 'O|O$O', ['', '', 'a'])
with self.assertRaisesRegex(TypeError,
r'function takes at least 1 positional argument
s
\
(
0
given
\
)
'
):
r'function takes at least 1 positional argument
\
(
0
given
\
)
'
):
parse((), {}, 'O|O$O', ['', '', 'a'])
with self.assertRaisesRegex(SystemError, r'Empty parameter name after
\
$
'
):
parse((1,), {}, 'O|$OO', ['', '', 'a'])
...
...
Misc/NEWS.d/next/C API/2018-07-24-11-57-35.bpo-34193.M6ch1Q.rst
0 → 100644
View file @
6326278e
Fix pluralization in TypeError messages in getargs.c and typeobject.c:
'1 argument' instead of '1 arguments' and '1 element' instead of '1 elements'.
Objects/typeobject.c
View file @
6326278e
...
...
@@ -5434,7 +5434,7 @@ check_num_args(PyObject *ob, int n)
return
1
;
PyErr_Format
(
PyExc_TypeError
,
"expected %d argument
s, got %zd"
,
n
,
PyTuple_GET_SIZE
(
ob
));
"expected %d argument
%s, got %zd"
,
n
,
n
==
1
?
""
:
"s"
,
PyTuple_GET_SIZE
(
ob
));
return
0
;
}
...
...
Python/getargs.c
View file @
6326278e
...
...
@@ -540,8 +540,10 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
levels
[
0
]
=
0
;
if
(
toplevel
)
{
PyOS_snprintf
(
msgbuf
,
bufsize
,
"expected %d arguments, not %"
PY_FORMAT_SIZE_T
"d"
,
n
,
len
);
"expected %d argument%s, not %"
PY_FORMAT_SIZE_T
"d"
,
n
,
n
==
1
?
""
:
"s"
,
len
);
}
else
{
PyOS_snprintf
(
msgbuf
,
bufsize
,
...
...
@@ -1718,12 +1720,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes %s %d positional arguments"
"%.200s%s takes %s %d positional argument
%
s"
" (%d given)"
,
(
fname
==
NULL
)
?
"function"
:
fname
,
(
fname
==
NULL
)
?
""
:
"()"
,
(
min
!=
INT_MAX
)
?
"at most"
:
"exactly"
,
max
,
nargs
);
max
,
max
==
1
?
""
:
"s"
,
nargs
);
}
return
cleanreturn
(
0
,
&
freelist
);
}
...
...
@@ -1797,12 +1801,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
if
(
skip
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes %s %d positional arguments"
"%.200s%s takes %s %d positional argument
%
s"
" (%d given)"
,
(
fname
==
NULL
)
?
"function"
:
fname
,
(
fname
==
NULL
)
?
""
:
"()"
,
(
Py_MIN
(
pos
,
min
)
<
i
)
?
"at least"
:
"exactly"
,
Py_MIN
(
pos
,
min
),
nargs
);
Py_MIN
(
pos
,
min
),
Py_MIN
(
pos
,
min
)
==
1
?
""
:
"s"
,
nargs
);
return
cleanreturn
(
0
,
&
freelist
);
}
...
...
@@ -2104,11 +2110,13 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
}
else
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes %s %d positional arguments (%d given)"
,
"%.200s%s takes %s %d positional argument
%
s (%d given)"
,
(
parser
->
fname
==
NULL
)
?
"function"
:
parser
->
fname
,
(
parser
->
fname
==
NULL
)
?
""
:
"()"
,
(
parser
->
min
!=
INT_MAX
)
?
"at most"
:
"exactly"
,
parser
->
max
,
nargs
);
parser
->
max
,
parser
->
max
==
1
?
""
:
"s"
,
nargs
);
}
return
cleanreturn
(
0
,
&
freelist
);
}
...
...
@@ -2152,12 +2160,14 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
if
(
i
<
pos
)
{
Py_ssize_t
min
=
Py_MIN
(
pos
,
parser
->
min
);
PyErr_Format
(
PyExc_TypeError
,
"%.200s%s takes %s %d positional arguments"
"%.200s%s takes %s %d positional argument
%
s"
" (%d given)"
,
(
parser
->
fname
==
NULL
)
?
"function"
:
parser
->
fname
,
(
parser
->
fname
==
NULL
)
?
""
:
"()"
,
min
<
parser
->
max
?
"at least"
:
"exactly"
,
min
,
nargs
);
min
,
min
==
1
?
""
:
"s"
,
nargs
);
}
else
{
keyword
=
PyTuple_GET_ITEM
(
kwtuple
,
i
-
pos
);
...
...
@@ -2417,9 +2427,9 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
else
PyErr_Format
(
PyExc_TypeError
,
"unpacked tuple should have %s%zd elements,"
"unpacked tuple should have %s%zd element
%
s,"
" but has %zd"
,
(
min
==
max
?
""
:
"at least "
),
min
,
nargs
);
(
min
==
max
?
""
:
"at least "
),
min
,
min
==
1
?
""
:
"s"
,
nargs
);
return
0
;
}
...
...
@@ -2436,9 +2446,9 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
else
PyErr_Format
(
PyExc_TypeError
,
"unpacked tuple should have %s%zd elements,"
"unpacked tuple should have %s%zd element
%
s,"
" but has %zd"
,
(
min
==
max
?
""
:
"at most "
),
max
,
nargs
);
(
min
==
max
?
""
:
"at most "
),
max
,
max
==
1
?
""
:
"s"
,
nargs
);
return
0
;
}
...
...
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