Skip to content

Commit 9dfa0fe

Browse files
authored
bpo-34637: Make the *start* argument for *sum()* visible as a keyword argument. (GH-9208)
1 parent 0fb9fad commit 9dfa0fe

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

Doc/library/functions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,9 @@ are always available. They are listed here in alphabetical order.
14881488
see :func:`math.fsum`\. To concatenate a series of iterables, consider using
14891489
:func:`itertools.chain`.
14901490

1491+
.. versionchanged:: 3.8
1492+
The *start* parameter can be specified as a keyword argument.
1493+
14911494
.. function:: super([type[, object-or-type]])
14921495

14931496
Return a proxy object that delegates method calls to a parent or sibling

Lib/test/test_builtin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,9 @@ def test_sum(self):
12971297
self.assertEqual(sum(iter(Squares(10))), 285)
12981298
self.assertEqual(sum([[1], [2], [3]], []), [1, 2, 3])
12991299

1300+
self.assertEqual(sum(range(10), 1000), 1045)
1301+
self.assertEqual(sum(range(10), start=1000), 1045)
1302+
13001303
self.assertRaises(TypeError, sum)
13011304
self.assertRaises(TypeError, sum, 42)
13021305
self.assertRaises(TypeError, sum, ['a', 'b', 'c'])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make the *start* argument to *sum()* visible as a keyword argument.

Python/bltinmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,8 @@ With an argument, equivalent to object.__dict__.");
22722272
sum as builtin_sum
22732273
22742274
iterable: object
2275-
start: object(c_default="NULL") = 0
22762275
/
2276+
start: object(c_default="NULL") = 0
22772277
22782278
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
22792279
@@ -2284,7 +2284,7 @@ reject non-numeric types.
22842284

22852285
static PyObject *
22862286
builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
2287-
/*[clinic end generated code: output=df758cec7d1d302f input=3b5b7a9d7611c73a]*/
2287+
/*[clinic end generated code: output=df758cec7d1d302f input=162b50765250d222]*/
22882288
{
22892289
PyObject *result = start;
22902290
PyObject *temp, *item, *iter;

Python/clinic/bltinmodule.c.h

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)