<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr">2018年6月21日(木) 20:27 Jeroen Demeyer <<a href="mailto:J.Demeyer@ugent.be" target="_blank" rel="noreferrer">J.Demeyer@ugent.be</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently, we have:<br>
<br>
>>> [].append == [].append<br>
False<br>
<br>
However, with a Python class:<br>
<br>
>>> class List(list):<br>
... def append(self, x): super().append(x)<br>
>>> List().append == List().append<br>
True<br>
<br>
In the former case, __self__ is compared using "is" and in the latter <br>
case, it is compared using "==".<br>
<br>
I think that comparing using "==" is the right thing to do because "is" <br>
is really an implementation detail. </blockquote></div></div><div dir="auto"><br></div><div dir="auto">I think "is" is correct because "bound to which object" is essential for bound (instance) methods.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Consider<br>
<br>
>>> (10000).bit_length == (10000).bit_length<br>
True<br>
>>> (10000).bit_length == (10000+0).bit_length<br>
False<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I'm OK for this difference.</div><div dir="auto">This comparison is what people shouldn't do, like 'id(10000) == id(10000+0)'</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I guess that's also the reason why CPython internally rarely uses "is" <br>
for comparisons.<br>
<br>
See also:<br>
- <a href="https://bugs.python.org/issue1617161" rel="noreferrer noreferrer noreferrer" target="_blank">https://bugs.python.org/issue1617161</a><br>
- <a href="https://bugs.python.org/issue33925" rel="noreferrer noreferrer noreferrer" target="_blank">https://bugs.python.org/issue33925</a><br>
<br>
Any opinions?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I think changing this may break some tricky code.</div><div dir="auto">Is it really worth enough to change?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br>
<br>
Jeroen.<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" rel="noreferrer noreferrer" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/songofacandy%40gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/songofacandy%40gmail.com</a><br>
</blockquote></div></div></div>