[ python-Bugs-1283491 ] nit for builtin sum doc

SourceForge.net noreply at sourceforge.net
Wed Sep 14 22:24:30 CEST 2005


Bugs item #1283491, was opened at 2005-09-07 02:18
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1283491&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 4
Submitted By: daishi harada (daishiharada)
Assigned to: Nobody/Anonymous (nobody)
Summary: nit for builtin sum doc

Initial Comment:
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.)

----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-09-14 22:24

Message:
Logged In: YES 
user_id=1188172

If we change the function signature in the docstring, we
must include the "defaults to 0" somewhere.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-09-08 04:37

Message:
Logged In: YES 
user_id=80475

"""
>>> sum([x] for x in xrange(10), start=[])
  File "<stdin>", 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).    

----------------------------------------------------------------------

Comment By: daishi harada (daishiharada)
Date: 2005-09-07 21:02

Message:
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 "<stdin>", 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 "<stdin>", 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 "<stdin>", 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.

----------------------------------------------------------------------

Comment By: daishi harada (daishiharada)
Date: 2005-09-07 21:02

Message:
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 "<stdin>", 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 "<stdin>", 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 "<stdin>", 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.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-09-07 05:11

Message:
Logged In: YES 
user_id=80475

While the proposed change is technically correct, I find the
original to be more informative.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1283491&group_id=5470


More information about the Python-bugs-list mailing list