<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 7, 2017 at 6:27 PM, Erik <span dir="ltr"><<a href="mailto:python@lucidity.plus.com" target="_blank">python@lucidity.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">Good point about list.extend(). I don't think __type_hint__ could help<br>
with .__contains__() or .count() or .remove(). E.g.:<br>
<br>
In [7]: lst = [1.0, 2.0, 1+0j, F(1,1)]<br>
In [8]: from fractions import Fraction as F<br>
In [9]: lst = [1.0, 2.0, 1+0j, F(1,1)]<br>
In [10]: 1 in lst<br>
Out[10]: True<br><br>
The list has absolutely nothing of the right type. Yet it contains an<br>
item, counts things that are equal, finds a position for an equal item.<br>
</span></blockquote>
<br>
Sure, but if the needle doesn't have the same type as the (homogeneous) haystack, then the rich comparison would still need to be done as a fallback (and would produce the result you indicate).<br></blockquote><div><br></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div>I<font face="monospace, monospace">n [22]: class Eq(int):</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> def __eq__(self, other):</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> return True</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace"> ....:</font></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">In [23]: four, five, six = Eq(4), Eq(5), Eq(6)</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">In [24]: lst = [four, five, six]</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">In [25]: lst.count(Eq(7))</span><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><font face="monospace, monospace">Out[25]: 3 </font></div></div></div></blockquote><div class="gmail_extra"><br></div><div class="gmail_extra">How would this work (other than saying "don't do that it's perverse")?<br clear="all"><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>