Duncan Booth <[EMAIL PROTECTED]> writes:

> Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
>> I've recently been bitten by [rebinding the var to what __iadd__
>> returns], and I don't understand the reasoning behind __iadd__'s
>> design.  I mean, what is the point of an *in-place* add operation
>> (and others) if it doesn't always work in-place?
>> 
> A very common use case is using it to increment a number:

I'm aware of that; but remember that there's still __add__.  It would
be sufficient for numbers not to implement __iadd__.  And, in fact,
they already don't:

>>> 1 .__add__(1)
2
>>> 1 .__iadd__(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__iadd__'

The current implementation of += uses __add__ for addition and
__iadd__ for addition that may or may not be in-place.  I'd like to
know the rationale for that design.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to