This isn't the first time around in this discussion of (abusing) 'sum()'.  Actually, I discussed the last round in my keynote at PyCon UK in 2013.  In particular, I actually discussed there already how Chris' latest version of 'sum()' breaks *existing* and *widespread* code.

My slides are at:

     http://gnosis.cx/pycon-uk-2013/Keynote-Ideas.pdf

Look at slides 24-26.  The TL;DR version: numpy arrays give different meanings to __add__() and __iadd__().  Chris' version breaks every program ever written that uses numpy.

On Wed, Aug 13, 2014 at 11:05 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote:

On Wed, Aug 13, 2014 at 10:46 AM, Steven D'Aprano <steve@pearwood.info> wrote:
That's another semantic change: sum() currently accepts iterators
(although not *infinite* iterators). This revision has now broken tens
of thousands of applications.

okay, how about:

def sum(items, start=0):
    first = True
    for item in items:
        if first:
            start = start + item
        else:
            start += item
    return start

I believe that has the same effect as my other two, but only adds the requirement that "value += item" behaves the same as "value = value + item".

Chris

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.