Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7447] Sum() doc and behavior mismatch

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Dec 5, 2009, 4:50 PM

Post #1 of 3 (175 views)
Permalink
[issue7447] Sum() doc and behavior mismatch

New submission from Terry J. Reedy <tjreedy [at] udel>:

"sum(iterable[, start])
Sums start and the items of an iterable from left to right and returns
the total. start defaults to 0. The iterable‘s items are normally
numbers, and are not allowed to be strings."

The last sentence is not currently true (3.1, assume also others).
It is the start value that cannot be a string.

>>> sum([1,2],'')
TypeError: sum() can't sum strings [use ''.join(seq) instead]

>>>sum(['xyz', 'pdq'], Zero()) # R Hettinger's universal zero class
'xyzpdq'
works because start is not a string

>>> sum(['a','b'])
TypeError: unsupported operand type(s) for +: 'int' and 'str'
passes type(start) != str and only fails because + fails.

I am filing this as a doc issue as the easiest fix for the discrepancy
between doc and behavior. But the fix could be a behavior change, though
certain to be controversial. Given that, my suggested revision is:
"The iterable‘s items are normally numbers. The start value is not
allowed to be a string."

I think this fits the followup sentence: "The fast, correct way to
concatenate a sequence of strings..."

----------
assignee: georg.brandl
components: Documentation
messages: 96013
nosy: georg.brandl, tjreedy
severity: normal
status: open
title: Sum() doc and behavior mismatch
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 6, 2009, 12:47 AM

Post #2 of 3 (149 views)
Permalink
[issue7447] Sum() doc and behavior mismatch [In reply to]

Changes by Raymond Hettinger <rhettinger [at] users>:


----------
assignee: georg.brandl -> rhettinger
nosy: +rhettinger

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Dec 7, 2009, 3:38 PM

Post #3 of 3 (130 views)
Permalink
[issue7447] Sum() doc and behavior mismatch [In reply to]

Ezio Melotti <ezio.melotti [at] gmail> added the comment:

There are also a couple more things that could be improved in the
documentation of sum():
1) add a note about the "performance trap" mentioned by Alex [1]
2) remove the reduce() example because, even if it's true for that
particular example, it's not always true for the general case (in the
py3 doc it has been removed already).

See also [2] and the other messages in that thread.

[1]: http://mail.python.org/pipermail/python-dev/2003-October/039529.html
[2]: http://mail.python.org/pipermail/python-dev/2003-October/039586.html

----------
nosy: +ezio.melotti
priority: -> normal
stage: -> needs patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7447>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.