On Tue, Jul 27, 2010 at 11:49 AM, Michael Foord <span dir="ltr"><<a href="mailto:fuzzyman@gmail.com">fuzzyman@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

On 27 July 2010 17:42, Alexander Belopolsky <span dir="ltr"><<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><div class="im">

<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On Tue, Jul 27, 2010 at 11:59 AM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>
..<br>
<div>>> So it doesn't help that 'in' may return something else than a bool<br>
>> because the method is called on the wrong object for your purposes.<br>
><br>
> Well that pretty much kills the proposal. I can't believe nobody<br>
> (including myself) figured this out earlier in the thread. :-(<br>
<br>
</div>It may kill a use case or two, but not the proposal.   In the<br>
libraries like numpy where all python containers get replaced, this is<br>
not an issue.   Also this problem invites __rcontains__ solution, </blockquote></div><div><br><br>Wasn't the lack of an __rcontains__ a problem for the web-sig guys trying to work out the bytes / strings issue?<br></div>

</div></blockquote><div><br>I think PJE wanted to implement a string type that was bytes+encoding (as opposed to using Python's native strings).  You can overload __add__ etc so everything works, but you couldn't make this work:<br>

<br>  encodedbytes(b'1234', 'utf8') in '12345'<br> <br>because '12345'.__contains__ would reject the encodedbytes type outright.<br><br>__rcontains__ would work because here '12345' would know that it didn't understand encodedbytes.  It wouldn't work for lists though, as [].__contains__ can handle *any* type, as it just tests for equality across all of its members.  So it's not like __radd__ because the original object can't know that it should defer to the other argument.<br>

</div></div><br>-- <br>Ian Bicking  |  <a href="http://blog.ianbicking.org">http://blog.ianbicking.org</a><br>