On Fri, Aug 11, 2006, Greg Ewing wrote:
> Phillip J. Eby wrote:
>> 
>> I think it's a warning sign because I *know* what augmented
>> assignment's semantics are supposed to be and I *still* try to use it
>> with setdefault() sometimes -- but only when I'm doing an augmented
>> assignment.  I never mistakenly try to assign to a function call in
>> any other circumstance.
>
> I think this problem arises because of the dual semantics of augmented
> assignment. One tends to have two *different* mental models of what it
> does, depending on whether the object in question is immutable:
>
>    (1) For immutable objects:
> 
>       x += y  <-->  x = x + y
> 
>    (2) For mutable objects:
> 
>       x += y  <-->  x.__iadd__(y)

What I try to do is always remember that

    x += y  <-->  x = x.__iadd__(y)

which mostly solves the problem.
-- 
Aahz ([EMAIL PROTECTED])           <*>         http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to