[Python-ideas] Fast sum() for non-numbers - why so much worries?

Joshua Landau joshua at landau.ws
Wed Jul 10 08:58:26 CEST 2013


On 10 July 2013 07:33, Paul Moore <p.f.moore at gmail.com> wrote:
> On 10 July 2013 07:09, Joshua Landau <joshua at landau.ws> wrote:
>>
>> I agree it's not totally backward-compatible, but AFAICT that's only
>> for broken code. __iadd__ should always just be a faster, in-place
>> __add__ and so this change should never cause problems in properly
>> written code. That makes it anything but a semantic change. It's the
>> same way people discuss the order of __hash__ calls on updates to code
>> but no-one calls it a *semantics* change.
>
> It will stop working for tuples (which have no __iadd__. Or were you
> suggesting trying __iadd__ and falling back to __add__ (that's more complex,
> obviously, and I don't think I'd assume it's "trivial" extra complexity) or
> special-caseing tuples (that's even more complex, and doesn't solve the
> problem for other iimmutables)?

Surely it just does the equivalent of "a += b", which handles fallback
for you. People don't write "a.__iadd__(b)" as much as they don't
write "a.__add__(b)". Python's C API has an inplace addition that
mimics this, btw.

And I'm not supporting special-casing anyway.


More information about the Python-ideas mailing list