<br><br><div class="gmail_quote">On Wed, Jun 1, 2011 at 9:56 AM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br></div>
Several times in that thread it was stated that<br>
<br>
--> a += 1<br>
<br>
is a shortcut for<br>
<br>
--> a.__iadd__(1)<br>
<br>
It seems to me that this is an implementation detail, and that the actual "longcut" is<br>
<br>
--> a = a + 1<br>
<br>...<br><font color="#888888">
<br>
~Ethan~<br></font></blockquote><div> </div><div>a += 1 is not a shortcut for a.__iadd__(1). It's a shortcut for a = a.__iadd(1). Otherwise this wouldn't work:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">>>> x = (1,)</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">>>> x += (2,)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">>>> x</font></div><div><font class="Apple-style-span" face="'courier new', monospace">(1, 2) </font></div>

</div><div><br></div><div>Note the difference between these two is one opcode:</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace"><div>>>> def f(x,y):</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>x += y</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div>>>> dis.dis(f)</div><div>  2           0 LOAD_FAST                0 (x)</div><div>              3 LOAD_FAST                1 (y)</div>
<div>
              6 <b>INPLACE_ADD</b>         </div><div>              7 STORE_FAST               0 (x)</div><div>             10 LOAD_CONST               0 (None)</div><div>             13 RETURN_VALUE        </div><div>>>> def g(x,y):</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>x = x + y</div><div><br></div><div>>>> dis.dis(g)</div><div>  2           0 LOAD_FAST                0 (x)</div><div>              3 LOAD_FAST                1 (y)</div>

<div>              6 <b>BINARY_ADD</b>          </div><div>              7 STORE_FAST               0 (x)</div><div>             10 LOAD_CONST               0 (None)</div><div>             13 RETURN_VALUE        </div></font></div>

<div><br></div></div><div>--- Bruce<div>Follow me: <a href="http://www.twitter.com/Vroo" target="_blank">http://www.twitter.com/Vroo</a> <a href="http://www.vroospeak.com">http://www.vroospeak.com</a></div><div>Latest tweet: <span style="font-family: Arial, 'Helvetica Neue', sans-serif; font-size: 14px; line-height: 17px; ">SO disappointed end of the world didn't happen AGAIN! <a href="http://twitter.com/#!/search?q=%23y2k" title="#y2k" rel="nofollow" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; white-space: nowrap; "><font color="#3333ff" style="background-color: rgb(255, 255, 255); "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline-block; ">#</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">y2k</span></font></a><font color="rgba(51, 51, 51, 0.59216)"> </font><a href="http://twitter.com/#!/search?q=%23rapture" title="#rapture" rel="nofollow" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; white-space: nowrap; "><font color="#3333ff"><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline-block; ">#</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">rapture</span></font></a><font color="rgba(51, 51, 51, 0.59216)"> </font>Now waiting for 2038!<font color="rgba(51, 51, 51, 0.59216)"> </font><a href="http://twitter.com/#!/search?q=%23unixrapture" title="#unixrapture" rel="nofollow" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; white-space: nowrap; "><font color="#3333ff"><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; display: inline-block; ">#</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">unixrapture</span></font></a></span><br>

</div><br></div>