[Python-ideas] All ideas together: Fast sum() for non-numbers

Joshua Landau joshua.landau.ws at gmail.com
Fri Jul 5 23:31:14 CEST 2013


On 5 July 2013 11:02, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
> I'm only +O on using __iadd__ in sum because it is unclear how useful this
> would be in real-world code, but does have a simple enough implementation that
> is still easily explained. I'd be -1 on adding custom hooks to improve
> the performance of specific types (such, adding tricks for speeding up
> joining a sequence of tuples or strings) as that makes the implementation
> harder and increases the conceptual complexity of the function as well.

This is a perfect summary of where I am on this proposal, but for
slightly different reasons.

If you special-case, either "sum(tuple_subclass)" is going to be
asymptotically slower (and hence code that duck-types should not rely
on it) or broken. Thus, special-casing is out of the window for me.

Using __iadd__, btw, cannot be a "bugfix", AFAIK, because it changes
behavior (subtly). But code that depends on that distinction is
broken, so I'm OK with it going forward. I appreciate the speed-up,
but as Steven convinced me it's not that big a deal. Hence +0.


More information about the Python-ideas mailing list