Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,9 @@ def test_sum(self):
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'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make the *start* argument to *sum()* visible as a keyword argument.
4 changes: 2 additions & 2 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions Python/clinic/bltinmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.