Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make *start* usable as a keyword argument for sum(). #78818

Closed
rhettinger opened this issue Sep 11, 2018 · 8 comments
Closed

Make *start* usable as a keyword argument for sum(). #78818

rhettinger opened this issue Sep 11, 2018 · 8 comments
Assignees
Labels
3.8 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 34637
Nosy @rhettinger, @gpshead, @serhiy-storchaka, @zooba, @tirkarthi
PRs
  • bpo-34637: Make the *start* argument for *sum()* visible as a keyword argument. #9208
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2018-09-12.17:57:52.700>
    created_at = <Date 2018-09-11.23:34:59.271>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Make *start* usable as a keyword argument for sum().'
    updated_at = <Date 2018-09-12.17:57:52.699>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2018-09-12.17:57:52.699>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2018-09-12.17:57:52.700>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2018-09-11.23:34:59.271>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34637
    keywords = ['patch']
    message_count = 8.0
    messages = ['325092', '325100', '325101', '325103', '325120', '325124', '325150', '325151']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'gregory.p.smith', 'serhiy.storchaka', 'steve.dower', 'xtreak']
    pr_nums = ['9208']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue34637'
    versions = ['Python 3.8']

    @rhettinger
    Copy link
    Contributor Author

    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.

    @rhettinger rhettinger added the 3.8 (EOL) end of life label Sep 11, 2018
    @rhettinger rhettinger self-assigned this Sep 11, 2018
    @rhettinger rhettinger added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 11, 2018
    @gpshead
    Copy link
    Member

    gpshead commented Sep 11, 2018

    +1 agreed.

    @zooba
    Copy link
    Member

    zooba commented Sep 11, 2018

    Woo! Thanks Raymond!

    @gpshead
    Copy link
    Member

    gpshead commented Sep 12, 2018

    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

    @serhiy-storchaka
    Copy link
    Member

    Is not this a duplicate of bpo-31141?

    @tirkarthi
    Copy link
    Member

    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

    @rhettinger
    Copy link
    Contributor Author

    New changeset 9dfa0fe by Raymond Hettinger in branch 'master':
    bpo-34637: Make the *start* argument for *sum()* visible as a keyword argument. (GH-9208)
    9dfa0fe

    @rhettinger
    Copy link
    Contributor Author

    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 bpo-31141. Will close that at well.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants