<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:arial,sans-serif">On Wed, Oct 18, 2017 at 6:56 PM, Paul Moore </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OK, looks like I've lost track of what this thread is about then.<br>
Sorry for the noise.<br>
<span class="HOEnZb"><font color="#888888">Paul<br>
</font></span><div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​No worries. I'm not sure I can tell what this thread is about either. Different people seem to have different ideas about that.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">My most recent point was that __contains__ already has to allow Python code to run on each iteration, so it is not the kind of code that Nick was referring to, and which I'm not convinced even exists.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">––Koos</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
On 18 October 2017 at 16:40, Koos Zevenhoven <<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>> wrote:<br>
> On Wed, Oct 18, 2017 at 6:36 PM, Paul Moore <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>> wrote:<br>
>><br>
>> On 18 October 2017 at 16:27, Koos Zevenhoven <<a href="mailto:k7hoven@gmail.com">k7hoven@gmail.com</a>> wrote:<br>
>> > So you're talking about code that would make a C-implemented Python<br>
>> > iterable<br>
>> > of strictly C-implemented Python objects and then pass this to something<br>
>> > C-implemented like list(..) or sum(..), while expecting no Python code<br>
>> > to be<br>
>> > run or signals to be checked anywhere while doing it. I'm not really<br>
>> > convinced that such code exists. But if such code does exist, it sounds<br>
>> > like<br>
>> > the code is heavily dependent on implementation details.<br>
>><br>
>> Well, the OP specifically noted that he had recently encountered<br>
>> precisely that situation:<br>
>><br>
>> """<br>
>> I recently came across a bug where checking negative membership<br>
>> (__contains__ returns False) of an infinite iterator will freeze the<br>
>> program.<br>
>> """<br>
>><br>
><br>
> No, __contains__ does not expect no python code to be run, because Python<br>
> code *can* run, as Serhiy in fact already demonstrated for another purpose:<br>
><br>
> On Wed, Oct 18, 2017 at 3:53 PM, Serhiy Storchaka <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>><br>
> wrote:<br>
>><br>
>> 18.10.17 13:22, Nick Coghlan пише:<br>
>>><br>
>>> 2.. These particular cases can be addressed locally using existing<br>
>>> protocols, so the chances of negative side effects are low<br>
>><br>
>><br>
>> Only the particular case `count() in count()` can be addressed without<br>
>> breaking the following examples:<br>
>><br>
>> >>> class C:<br>
>> ...     def __init__(self, count):<br>
>> ...         self.count = count<br>
>> ...     def __eq__(self, other):<br>
>> ...         print(self.count, other)<br>
>> ...         if not self.count:<br>
>> ...             return True<br>
>> ...         self.count -= 1<br>
>> ...         return False<br>
>> ...<br>
>> >>> import itertools<br>
>> >>> C(5) in itertools.count()<br>
>> 5 0<br>
>> 4 1<br>
>> 3 2<br>
>> 2 3<br>
>> 1 4<br>
>> 0 5<br>
>> True<br>
><br>
><br>
><br>
> Clearly, Python code *does* run from within itertools.count.__contains__(.<wbr>.)<br>
><br>
><br>
> ––Koos<br>
><br>
><br>
> --<br>
> + Koos Zevenhoven + <a href="http://twitter.com/k7hoven" rel="noreferrer" target="_blank">http://twitter.com/k7hoven</a> +<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven" target="_blank">http://twitter.com/k7hoven</a> +</div>
</div></div>