[Python-ideas] Fast sum summary [was Re: Fast sum() for non-numbers - why so much worries?]
Sergey
sergemp at mail.ru
Tue Jul 16 07:39:11 CEST 2013
On Jul 13, 2013 Paul Moore wrote:
>> So you can, kind of, say that sum was DESIGNED to have special cases
>> from the very beginning.
>>
>
> Thanks for the reference. That's the *original* implementation. So why does
> the current sum() not do this? You need to locate the justification for the
> removal of this special case
As I already said the problem was in mixed list of strings and
non-strings[1]. Later Guido suggested to check second argument and
raise TypeError for strings [2], and Alex Martelli answered [3]
"I like this!!!" and implemented it.
> and explain why that reason no longer applies.
It still does, and it's still there — sum() still has a special case
check for strings (and bytes, and bytearrays) rejecting it.
But my patch does not use that approach, it does not call external
join-like function, so it can correctly recover from mixed lists
case. Meaning, my patch does not have the bug of initial sum().
--
[1]http://mail.python.org/pipermail/python-dev/2003-April/034854.html
[2]http://mail.python.org/pipermail/python-dev/2003-April/034853.html
[3]http://mail.python.org/pipermail/python-dev/2003-April/034855.html
More information about the Python-ideas
mailing list