Issue 1283491: nit for builtin sum doc (original) (raw)

Created on 2005-09-07 00:18 by daishiharada, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg26221 - (view) Author: daishi (daishiharada) Date: 2005-09-07 00:18
the docstring signature for sum in bltinmodule.c should be changed from: sum(sequence, start=0) to: sum(sequence[, start]) to reflect the current implementation in builtin_sum. (or else the implementation should be changed to accept kwargs.)
msg26222 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-09-07 03:11
Logged In: YES user_id=80475 While the proposed change is technically correct, I find the original to be more informative.
msg26223 - (view) Author: daishi (daishiharada) Date: 2005-09-07 19:02
Logged In: YES user_id=493197 This is relatively minor so I don't mean to push particularly hard, but I'd like to at least show how the docstring made me stray: >>> sum([x] for x in xrange(10)) Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'int' and 'list' >>> help(sum) Help on built-in function sum in module __builtin__: sum(...) sum(sequence, start=0) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start'. When the sequence is empty, returns start. >>> sum([x] for x in xrange(10), start=[]) File "", line 1 SyntaxError: invalid syntax # The problem above is orthogonal to the issue in this bug, # but I wonder if at some point we'll be able to write such? >>> sum(([x] for x in xrange(10)), start=[]) Traceback (most recent call last): File "", line 1, in ? TypeError: sum() takes no keyword arguments # examine lib docs, which give the signature: # sum( sequence[, start]) >>> sum(([x] for x in xrange(10)), []) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> # examine bltinmodule.c to confirm that # sum doesn't accept kwargs.
msg26224 - (view) Author: daishi (daishiharada) Date: 2005-09-07 19:02
Logged In: YES user_id=493197 This is relatively minor so I don't mean to push particularly hard, but I'd like to at least show how the docstring made me stray: >>> sum([x] for x in xrange(10)) Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'int' and 'list' >>> help(sum) Help on built-in function sum in module __builtin__: sum(...) sum(sequence, start=0) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start'. When the sequence is empty, returns start. >>> sum([x] for x in xrange(10), start=[]) File "", line 1 SyntaxError: invalid syntax # The problem above is orthogonal to the issue in this bug, # but I wonder if at some point we'll be able to write such? >>> sum(([x] for x in xrange(10)), start=[]) Traceback (most recent call last): File "", line 1, in ? TypeError: sum() takes no keyword arguments # examine lib docs, which give the signature: # sum( sequence[, start]) >>> sum(([x] for x in xrange(10)), []) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> # examine bltinmodule.c to confirm that # sum doesn't accept kwargs.
msg26225 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-09-08 02:37
Logged In: YES user_id=80475 """ >>> sum([x] for x in xrange(10), start=[]) File "", line 1 SyntaxError: invalid syntax # The problem above is orthogonal to the issue in this bug, # but I wonder if at some point we'll be able to write such? """ FYI, the answer is no. The requirement for parenthesis cannot change. To see why, parse this: f(g(t) for t in a, b).
msg26226 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-14 20:24
Logged In: YES user_id=1188172 If we change the function signature in the docstring, we must include the "defaults to 0" somewhere.
msg26227 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-10-12 12:33
Logged In: YES user_id=849994 Fixed in rev. 52315.
History
Date User Action Args
2022-04-11 14:56:12 admin set github: 42348
2005-09-07 00🔞50 daishiharada create