Augmented Assignement (was: Re: PEP scepticism)

Tim Hochberg tim.hochberg at ieee.org
Mon Jul 2 13:01:14 EDT 2001


"Paul Prescod" <paulp at ActiveState.com> wrote in message
[SNIP]
> That's exactly the problem. The millions of newbies who begged for this
> feature didn't want a short form for a method call. They wanted a short
> form for a repetitive assignment pattern. The feature as implemented
> tries to make them happy and at the same time tries to make the NumPy
> guys happy. If we had chosen to ONLY make the NumPy guys happy then the
> feature would never have got in -- after all it is isomorphic to a
> method call. I think the newbies were sacrificed on the alter of the
> Numeric Dieties.

That's not right.  The behaviour that is being complained here has very
little to do with NumPy. It would have been perfectly possible to make the
augmented assigment operators behave as you desire (nonmutating) for all of
the builtin types, while leaving them as they are for Numeric. All that it
would require would be defining _iadd__ for lists and other offending
objects to be equivalent to:

def __iadd__(self, other):
   return self + other

instead of:

def __iadd__(self, other):
   self.extend(other)
   return self

as it is now.

Someone made a decision at some point that the builtin mutable types should
mutated by augmented assigment. If the newbies were sacrificed on somebody's
alter, it was not NumPy's.

-tim





More information about the Python-list mailing list