<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Jan 23, 2017 1:12 PM, "Britton, Gerald" <<a href="mailto:Gerald.Britton@td.com">Gerald.Britton@td.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div class="m_7657605112096263134WordSection1">
<pre><span style="color:black">On 23/01/17 02:56 PM, Gerald Britton wrote:<u></u><u></u></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> On Jan 23, 2017 11:07 AM, "Soni L." <<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">fakedme+py at gmail.com</a> <u></u><u></u></i></span></pre>
<pre><span style="color:black">><i> <mailto:<a href="mailto:fakedme%25" target="_blank">fakedme%</a><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">2Bpy at gmail.com</a>>> wrote:<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> On 23/01/17 01:52 PM, Gerald Britton wrote:<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> [snip]<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> >I propose `x .= y` -> `x = x . y`, for any `y`.<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> [snip]<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> I think you mean "any y that is a member of x"<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> Since it desugars into `x = x.y`, you can literally use anything<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i> for `y`.<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> x .= __call__().whatever().unwrap() * 3<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> is equivalent to<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> x = x.__call__().whatever().<wbr>unwrap() * 3<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> and<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> x .= 1<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> is equivalent to<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> x = x.1<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> which is equivalent to<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> SyntaxError: invalid syntax<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> Also, note that this syntax means that x will be rebound to<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i> the result of calling x.y, whatever that is (frequently,<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i> None, for mutating methods)<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> In general, you can't count on methods to return references<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i> to their instances, even though it's handy for fluent coding,<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i> so this side effect may be unexpected to some<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> This is why it's for use with **immutable** objects.<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> That's a problem with your original example:<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> >long_name = mkbuilder()<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> >long_name = long_name.seta(a)<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> >long_name = long_name.setb(b)<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> >y = long_name.build()<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> What do the methods seta and setb return? If they don't<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i> return "self" you've got a problem. I think.<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> They don't return self. Ever. The value bound to long_name is<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i> immutable, like an integer. They return a new instance.<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> Then long_name isn't immutable. It changes with every line. That can <u></u><u></u></i></span></pre>
<pre><span style="color:black">><i> lead to nasty bugs if you count on its immutability.<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> Easy to see. Just print long_name after each call.<u></u><u></u></i></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">You're mixing up value immutability with name immutability. The name <u></u><u></u></span></pre>
<pre><span style="color:black">isn't immutable, but:</span></pre></div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Er...No. I'm not confused at all, unless you define immutability in a new way.. you said that the "value bound to long_name is immutable." It's not. Your example below proves it. </div><div dir="auto"><br></div><div dir="auto">An immutable object is one whose state cannot be modified once set. That's not happening here. The state of the object bound to long_name, which is a pointer to an instance of you class, changes with each line.</div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_7657605112096263134WordSection1"><pre><span style="color:black"><u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">long_name = mkbuilder()<u></u><u></u></span></pre>
<pre><span style="color:black">x = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">long_name .= seta("a")<u></u><u></u></span></pre>
<pre><span style="color:black">y = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">long_name .= setb("b")<u></u><u></u></span></pre>
<pre><span style="color:black">z = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">print(x) # a = None, b = None<u></u><u></u></span></pre>
<pre><span style="color:black">print(y) # a = "a", b = None<u></u><u></u></span></pre>
<pre><span style="color:black">print(z) # a = "a", b = "b"<u></u><u></u></span></pre>
<pre><span style="color:black">print(x is y) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(x is z) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(y is z) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(long_name is z) # True<u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">See also:<u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">long_name = 1<u></u><u></u></span></pre>
<pre><span style="color:black">x = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">long_name += 1<u></u><u></u></span></pre>
<pre><span style="color:black">y = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">long_name += 1<u></u><u></u></span></pre>
<pre><span style="color:black">z = long_name<u></u><u></u></span></pre>
<pre><span style="color:black">print(x) # 1<u></u><u></u></span></pre>
<pre><span style="color:black">print(y) # 2<u></u><u></u></span></pre>
<pre><span style="color:black">print(z) # 3<u></u><u></u></span></pre>
<pre><span style="color:black">print(x is y) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(x is z) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(y is z) # False<u></u><u></u></span></pre>
<pre><span style="color:black">print(long_name is z) # True<u></u><u></u></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> FWIW why can't you just write:<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> x.y<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> or for your example:<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> long_name.seta(a)<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i> ?<u></u><u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">>><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i> See the IRC bot builder example, it should be more clear. (It's<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i> about forking the builder.)<u></u><u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black">><i><u></u> <u></u></i></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
</div>
<p><font face="Arial" style="font-size:8pt"><br>
<br>
If you wish to unsubscribe from receiving commercial electronic messages from TD Bank Group, please click <a href="http://www.td.com/tdoptout" target="_blank">here</a> or go to the following web address: <a href="http://www.td.com/tdoptout" target="_blank">www.td.com/tdoptout</a><br>
Si vous souhaitez vous désabonner des messages électroniques de nature commerciale envoyés par Groupe Banque TD veuillez cliquer <a href="http://www.td.com/tddesab" target="_blank">ici</a> ou vous rendre à l'adresse <a href="http://www.td.com/tddesab" target="_blank">www.td.com/tddesab</a>
</font></p>
<p><font face="Arial" style="font-size:8pt"><br>
NOTICE: Confidential message which may be privileged. Unauthorized use/disclosure prohibited. If received in error, please go to <a href="http://www.td.com/legal" target="_blank">www.td.com/legal</a> for instructions.<br>
AVIS : Message confidentiel dont le contenu peut être privilégié. Utilisation/divulgation interdites sans permission. Si reçu par erreur, prière d'aller au <a href="http://www.td.com/francais/avis_juridique" target="_blank">www.td.com/francais/avis_<wbr>juridique</a> pour des instructions.</font></p>
</div>
</blockquote></div><br></div></div></div>