classification
Title: Make *start* usable as a keyword argument for sum().
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: gregory.p.smith, rhettinger, serhiy.storchaka, steve.dower, xtreak
Priority: normal Keywords: patch

Created on 2018-09-11 23:34 by rhettinger, last changed 2018-09-12 17:57 by rhettinger. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9208 merged rhettinger, 2018-09-12 00:34
Messages (8)
msg325092 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-09-11 23:34
Currently, we can write:

    >>> sum(range(10), 50)
    95

What we want to allow:

    >>> sum(range(10), start=50)
    95

The positional form would still be allowed.
msg325100 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2018-09-11 23:54
+1 agreed.
msg325101 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-09-11 23:57
Woo! Thanks Raymond!
msg325103 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2018-09-12 00:11
I suggest also allowing the first argument to be a keyword named sequence= as well.  (along the philosophy of positional only arguments on APIs that happen to be implemented in C in CPython are a bad legacy)

pypy already uses these names:
 https://bitbucket.org/pypy/pypy/src/4cbeaa8bf545332c36ae277019772aa432693e4c/pypy/module/__builtin__/app_functional.py?at=default&fileviewer=file-view-default#app_functional.py-41
msg325120 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-12 04:53
Is not this a duplicate of issue31141?
msg325124 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2018-09-12 05:59
There doesn't seem to be any performance regression hoping that I am doing the benchmarks correctly. Some numbers for the PR.

# Master

git checkout master
git clean -xdf && ./configure && make -s -j4

$ cpython git:(master) ./python.exe
Python 3.8.0a0 (heads/master:731ff68eee, Sep 12 2018, 11:19:46)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

$ cpython git:(master) repeat 10 ./python.exe -m timeit "sum(range(10), 50)"
500000 loops, best of 5: 635 nsec per loop
500000 loops, best of 5: 682 nsec per loop
500000 loops, best of 5: 637 nsec per loop
500000 loops, best of 5: 648 nsec per loop
500000 loops, best of 5: 618 nsec per loop
500000 loops, best of 5: 621 nsec per loop
500000 loops, best of 5: 653 nsec per loop
500000 loops, best of 5: 624 nsec per loop
500000 loops, best of 5: 671 nsec per loop
500000 loops, best of 5: 659 nsec per loop

git fetch upstream pull/9208/head:sum-start-keyword
git checkout sum-start-keyword
git clean -xdf && ./configure && make -s -j4

$ cpython git:(sum-start-keyword) ./python.exe
Python 3.8.0a0 (heads/sum-start-keyword:71b890cd56, Sep 12 2018, 11:23:02)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

$ cpython git:(sum-start-keyword) repeat 10 ./python.exe -m timeit "sum(range(10), 50)"
500000 loops, best of 5: 655 nsec per loop
500000 loops, best of 5: 662 nsec per loop
500000 loops, best of 5: 669 nsec per loop
500000 loops, best of 5: 656 nsec per loop
500000 loops, best of 5: 666 nsec per loop
500000 loops, best of 5: 642 nsec per loop
500000 loops, best of 5: 638 nsec per loop
500000 loops, best of 5: 628 nsec per loop
500000 loops, best of 5: 684 nsec per loop
500000 loops, best of 5: 648 nsec per loop

$ cpython git:(sum-start-keyword) repeat 10 ./python.exe -m timeit "sum(range(10), start=50)"
500000 loops, best of 5: 637 nsec per loop
500000 loops, best of 5: 677 nsec per loop
500000 loops, best of 5: 649 nsec per loop
500000 loops, best of 5: 660 nsec per loop
500000 loops, best of 5: 692 nsec per loop
500000 loops, best of 5: 704 nsec per loop
500000 loops, best of 5: 638 nsec per loop
500000 loops, best of 5: 659 nsec per loop
500000 loops, best of 5: 637 nsec per loop
500000 loops, best of 5: 699 nsec per loop

I haven't tested the other PR serhiy mentioned since it has merge conflicts and I think it uses the same approach with argument clinic.


Thanks
msg325150 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-09-12 17:54
New changeset 9dfa0fe587eae3626ffc973680c6a17f35de3864 by Raymond Hettinger in branch 'master':
bpo-34637: Make the *start* argument for *sum()* visible as a keyword argument. (GH-9208)
https://github.com/python/cpython/commit/9dfa0fe587eae3626ffc973680c6a17f35de3864
msg325151 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-09-12 17:57
Discussed exposure of the first argument with GPS and agreed that we don't want people writing API sum(iterable=[10,20,30], start=0).

Serhiy, yes this is a duplicate/superseder of issue31141.   Will close that at well.
History
Date User Action Args
2019-03-31 06:28:59xtreaklinkissue36491 superseder
2018-09-12 17:59:37rhettingerlinkissue31141 superseder
2018-09-12 17:57:52rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg325151

stage: patch review -> resolved
2018-09-12 17:54:10rhettingersetmessages: + msg325150
2018-09-12 05:59:58xtreaksetmessages: + msg325124
2018-09-12 04:53:33serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg325120
2018-09-12 03:51:37xtreaksetnosy: + xtreak
2018-09-12 00:34:32rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request8642
2018-09-12 00:11:03gregory.p.smithsetmessages: + msg325103
2018-09-11 23:57:25steve.dowersetnosy: + steve.dower
messages: + msg325101
2018-09-11 23:54:35gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg325100
2018-09-11 23:34:59rhettingercreate