[issue41740] Improve error message for string concatenation via `sum`

Vedran Čačić report at bugs.python.org
Mon Sep 7 23:50:18 EDT 2020


Vedran Čačić <vedgar at gmail.com> added the comment:

The fact that you've forgotten about it is exactly why sum tries to educate you (despite Python being "the language of consenting adults" in most other aspects). The problem (why it doesn't do a good job in that aspect) is that people usually expect sum to act like a 2-arg form of functools.reduce, while in fact it acts like a 3-arg form, with 0 as the initializer.

I doubt that Python will change regarding that, but you can sharpen your intuition by asking yourself: what do you expect sum([]) to be? If 0, then you're inconsistent. :-)

----------
nosy: +veky

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41740>
_______________________________________


More information about the Python-bugs-list mailing list