In the statistics module, I have a private _sum() function which tried
really hard to deal with high-accuracy sums of mixed arbitrary numeric
types without compromising too badly on speed, and it's much harder than
it seems. Trying to handle non-numeric types too increases the
complexity significantly. If you're smarter than me (I expect that many
of you probably are) and believe that you can write a version of sum()
which:
(1) is fast
(2) has better than O(N**2) performance
(3) is correct
(4) is accurate
(5) handles INFs and NANs (for those types which have them)
(6) handles mixed types (for those types which allow mixing)
(7) honours subclasses with custom __add__ and __radd__ methods
(8) and keeps the expected semantics that sum() is like repeated
addition (or concatenation)
and does so for *both* numeric and non-numeric cases (like strings,
bytes, tuples, lists), then PLEASE write some code and publish it. I for
one would love to see it or use it for the statistics module. But until
you have tried writing such a thing, whether in C or Python, I think
you're probably underestimating how hard it is and how fragile the
result will be.