<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:36 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">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 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 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 like<br>
> the code is heavily dependent on implementation details.<br>
<br>
</span>Well, the OP specifically noted that he had recently encountered<br>
precisely that situation:<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><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></div></div></blockquote><div><br></div><div class="gmail_default" style="font-family:monospace,monospace">No, __contains__ does not expect no python code to be run, because Python code *can* run, as Serhiy in fact already demonstrated for another purpose:</div><div class="gmail_default" style="font-family:monospace,monospace"><div class="gmail_default"></div><br style="font-family:arial,sans-serif"><div class="gmail_quote" style="font-family:arial,sans-serif">On Wed, Oct 18, 2017 at 3:53 PM, Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.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">18.10.17 13:22, Nick Coghlan пише:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">2.. These particular cases can be addressed locally using existing protocols, so the chances of negative side effects are low<br></blockquote><br>Only the particular case `count() in count()` can be addressed without 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</blockquote></div></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Clearly, Python code *does* run from within itertools.count.__contains__(..)</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">––Koos<br></div></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven" target="_blank">http://twitter.com/k7hoven</a> +</div>
</div></div>