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
Start should be a keyword argument of the built-in sum #75324
Comments
The built-in function sum takes an optional argument "start" to specify what value to start adding from (defaults to 0). This argument should be a keyword argument in order to match the other built-in functions such as:
This patch allows users to write:
which previously raised "TypeError: sum() takes no keyword arguments". Since the only change is making an optional positional argument into a keyword argument, this has no effect on any existing code using the current convention of:
|
This seems like a reasonable enhancement to Since 2.7 is in feature freeze, this can only apply to 3.7. |
Lisa, would you like to take this one? |
Adding this feature is so easy as moving '/' in Argument Clinic declaration one line up. I don't think it is worth to allow passing the first argument as a keyword argument. Check what performance effect of this change on simple calls sum(()), sum((), 0). |
I ran some timing tests of the patch I submitted to compare it to the current build of Python. Using timit on the current master branch I got:
And for the patched version:
However my patch wasn't just the simple argument clinic change suggested by serhiy.storchaka, so maybe that would be more efficient and easier to understand. |
Your tests show that there is a performance regression of getting rid of Argument Clinic (in addition to increasing the maintenance cost of the code that was generated previously). Try to use the simple Argument Clinic change (it can has non-zero cost too, but I expect that its penalty is much smaller). |
Hi Mark, Are you able to make the Argument Clinic change the Serhiy suggested to come up with new benchmarks? Thanks! |
First than to allow this argument be passes by keyword, we mast choose its name. See the discussion "Start argument for itertools.accumulate()" on Python-ideas (https://mail.python.org/pipermail/python-ideas/2018-April/049649.html). |
I concur. Would you mind to add a test to make sure that passing the first argument as the "iterable" keyword doesn't work? "iterable" name comes from the Doc/library/functions.rst documentation and from the docstring. |
In 2.6 it was "sequence". |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: