Augmented Assignement (was: Re: PEP scepticism)

Carsten Geckeler uioziaremwpl at spammotel.com
Tue Jul 3 11:38:05 EDT 2001


On Tue, 3 Jul 2001, Fredrik Lundh wrote:

> Carsten wrote:
>
> > Well, the Python world before augmented assignment was quite simple:
> > Operators never changed the objects they acted on.
>
> nothing prevents __add__ from changing the objects.

Thank you very much for deleting my next sentence which clearly stated
that it can be done, of course, by a user defined object by operator
overloading.  I'm sticking at first with builtin types which behave in
that way.  And I hope most authors also try to do the same in this case
for clearity.

> > Now we have augmented assignments.  x=+y _can_ change the object
> > bound to x, depending if x is mutable or immutable.
>
> has nothing to do with mutability, and all to do with how the
> __iadd__ method is implemented:
>
>     + is an alias for __add__
>     += is an alias for __iadd__
>
> as for all other operators, the exact semantics are up to the
> type/class implementation.

Again, my argument was for builtin types.  And for them the distinction is
made for mutable and immutable types.

That user defined classes can define some strange operator overloading is
o.k.  But allowing people doing things does not neccessarily mean that
thay should do it, especially when it's not logical.

Cheers, Carsten
-- 
Carsten Geckeler





More information about the Python-list mailing list