restriction on sum: intentional bug?

Jon Clements joncle at googlemail.com
Fri Oct 16 21:01:41 EDT 2009


On Oct 17, 1:16 am, Terry Reedy <tjre... at udel.edu> wrote:
> Alan G Isaac wrote:
>
> > As Tim explained in detail, and as Peter
> > explained with brevity, whether it will
> > happen or not, it should happen.  This
> > conversation has confirmed that current
> > behavior is a wart: an error is raised
> > despite correct semantics. Ugly!
>
> The fact that two or three people who agree on something agree on the
> thing that they agree on confirms nothing. One could just as well argue
> that summing anything but numbers is semantically incoherent, not
> correct. Certainly, my dictionary points in that direction.
>
> tjr

I agree here. I don't think it's a case of "warning about
inefficiency" that Python
doesn't sum strings, but rather that 'summing' strings doesn't make
sense.

An OTT example could be sum(['010111010', '372']) # Binary and decimal

Sum should return a *numeric* result, it has no way to do anything
sensible
with strings -- that's up to the coder and I think it'd be an error in
Python
to not raise an error.

Jon.



More information about the Python-list mailing list