Assignment operator?

Huaiyu Zhu hzhu at mars.localdomain
Fri Apr 19 02:30:57 EDT 2002


Ante Bagaric <abagaric_NOSPAM at rest-art.hr> wrote:

>> I think what you haven't understood is the update in-place semantics that
>> mutable object implementations *may* choose to adopt. Otherwise you seem
>to
>> have it down pat.
>
>Hmm, and the compiler doesn't know in advance what object a name references,
>so it has no choice but to flag '+=' as rebinding operation even if it is
>not
>the case. It doesn't sound nice, but I admit there's no obvious alternative
>that
>comes to mind. This whole namespace and local/global issue has an aura of
>'unfinishness' around it :)

At the time when it was introduced, there have been quite a lot of oposition
to the fact that its behavior depends on the mutability of the object,
something that is not always known in advance.  There were even several
proposals that suggested different spelling for "always rebind", "always in
place", and "depending on mutability".  In the end one spelling was adopted
for the current behavior.

IIRC, the suggested spellings include '+=', '+!' and '+:'.

Since then there have been many questions here about the exact behavior.
It is similar to the question about / behavior between ints and floats.  But
your observation of its interaction with scoping rules appears to be new.
This suggests there is a real benefit to have an "always in place" operator.


Huaiyu



More information about the Python-list mailing list