__iadd__ and fellows missing (Python 2.2)

Delaney, Timothy tdelaney at avaya.com
Mon Apr 22 20:42:07 EDT 2002


> From: Jeff Shannon [mailto:jeff at ccvcorp.com]
> 
> While there might be some theoretical argument for considering 
> augmented assignment on immutable types to be an error, keep in 
> mind that practicality beats purity.  Making augmented assignment 
> on integers into an error would, in practice, be quite silly.

Especially as it is the place I am most likely to use it ...

There is actually nothing stopping a mutable object from implementing a = a
+ b semantics in __iadd__ and fellows either ... or having different binding
semantics in __iadd__, __imul__, etc ... (although the latter would be truly
horrendous).

Basically, if you don't want any chance of an object being mutated by
(optionally) in-place operations, make a copy of the object and operate on
that.

Tim Delaney





More information about the Python-list mailing list