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
9dfa0fe5
Commit
9dfa0fe5
authored
Sep 12, 2018
by
Raymond Hettinger
Committed by
GitHub
Sep 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34637: Make the *start* argument for *sum()* visible as a keyword argument. (GH-9208)
parent
0fb9fadd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
8 deletions
+16
-8
Doc/library/functions.rst
Doc/library/functions.rst
+3
-0
Lib/test/test_builtin.py
Lib/test/test_builtin.py
+3
-0
Misc/NEWS.d/next/Core and Builtins/2018-09-11-17-25-44.bpo-34637.HSLqY4.rst
...ore and Builtins/2018-09-11-17-25-44.bpo-34637.HSLqY4.rst
+1
-0
Python/bltinmodule.c
Python/bltinmodule.c
+2
-2
Python/clinic/bltinmodule.c.h
Python/clinic/bltinmodule.c.h
+7
-6
No files found.
Doc/library/functions.rst
View file @
9dfa0fe5
...
...
@@ -1488,6 +1488,9 @@ are always available. They are listed here in alphabetical order.
see :func:`math.fsum`\. To concatenate a series of iterables, consider using
:func:`itertools.chain`.
.. versionchanged:: 3.8
The *start* parameter can be specified as a keyword argument.
.. function:: super([type[, object-or-type]])
Return a proxy object that delegates method calls to a parent or sibling
...
...
Lib/test/test_builtin.py
View file @
9dfa0fe5
...
...
@@ -1297,6 +1297,9 @@ class BuiltinTest(unittest.TestCase):
self
.
assertEqual
(
sum
(
iter
(
Squares
(
10
))),
285
)
self
.
assertEqual
(
sum
([[
1
],
[
2
],
[
3
]],
[]),
[
1
,
2
,
3
])
self
.
assertEqual
(
sum
(
range
(
10
),
1000
),
1045
)
self
.
assertEqual
(
sum
(
range
(
10
),
start
=
1000
),
1045
)
self
.
assertRaises
(
TypeError
,
sum
)
self
.
assertRaises
(
TypeError
,
sum
,
42
)
self
.
assertRaises
(
TypeError
,
sum
,
[
'a'
,
'b'
,
'c'
])
...
...
Misc/NEWS.d/next/Core and Builtins/2018-09-11-17-25-44.bpo-34637.HSLqY4.rst
0 → 100644
View file @
9dfa0fe5
Make the *start* argument to *sum()* visible as a keyword argument.
Python/bltinmodule.c
View file @
9dfa0fe5
...
...
@@ -2272,8 +2272,8 @@ With an argument, equivalent to object.__dict__.");
sum as builtin_sum
iterable: object
start: object(c_default="NULL") = 0
/
start: object(c_default="NULL") = 0
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
...
...
@@ -2284,7 +2284,7 @@ reject non-numeric types.
static
PyObject
*
builtin_sum_impl
(
PyObject
*
module
,
PyObject
*
iterable
,
PyObject
*
start
)
/*[clinic end generated code: output=df758cec7d1d302f input=
3b5b7a9d7611c73a
]*/
/*[clinic end generated code: output=df758cec7d1d302f input=
162b50765250d222
]*/
{
PyObject
*
result
=
start
;
PyObject
*
temp
,
*
item
,
*
iter
;
...
...
Python/clinic/bltinmodule.c.h
View file @
9dfa0fe5
...
...
@@ -608,7 +608,7 @@ exit:
}
PyDoc_STRVAR
(
builtin_sum__doc__
,
"sum($module, iterable,
start=0, /
)
\n
"
"sum($module, iterable,
/, start=0
)
\n
"
"--
\n
"
"
\n
"
"Return the sum of a
\'
start
\'
value (default: 0) plus an iterable of numbers
\n
"
...
...
@@ -618,20 +618,21 @@ PyDoc_STRVAR(builtin_sum__doc__,
"reject non-numeric types."
);
#define BUILTIN_SUM_METHODDEF \
{"sum", (PyCFunction)builtin_sum, METH_FASTCALL, builtin_sum__doc__},
{"sum", (PyCFunction)builtin_sum, METH_FASTCALL
|METH_KEYWORDS
, builtin_sum__doc__},
static
PyObject
*
builtin_sum_impl
(
PyObject
*
module
,
PyObject
*
iterable
,
PyObject
*
start
);
static
PyObject
*
builtin_sum
(
PyObject
*
module
,
PyObject
*
const
*
args
,
Py_ssize_t
nargs
)
builtin_sum
(
PyObject
*
module
,
PyObject
*
const
*
args
,
Py_ssize_t
nargs
,
PyObject
*
kwnames
)
{
PyObject
*
return_value
=
NULL
;
static
const
char
*
const
_keywords
[]
=
{
""
,
"start"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"O|O:sum"
,
_keywords
,
0
};
PyObject
*
iterable
;
PyObject
*
start
=
NULL
;
if
(
!
_PyArg_UnpackStack
(
args
,
nargs
,
"sum"
,
1
,
2
,
if
(
!
_PyArg_ParseStackAndKeywords
(
args
,
nargs
,
kwnames
,
&
_parser
,
&
iterable
,
&
start
))
{
goto
exit
;
}
...
...
@@ -710,4 +711,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return
return_value
;
}
/*[clinic end generated code: output=
9f17c7a87d740374
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
eb6d08a32e7c83b6
input=a9049054013a1b77]*/
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