<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 20, 2013 at 12:53 PM, Stephen J. Turnbull <span dir="ltr"><<a href="mailto:stephen@xemacs.org" target="_blank">stephen@xemacs.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Neil Girdhar writes:<br>
<br>
 > Many different solutions would fix the problems I've seen.  My<br>
 > suggestion is that Reiterable should be define as an iteratable for<br>
 > which calling the __iter__ method yields the same elements in the<br>
 > same order irrespective of whether __iter__ is called while a<br>
 > previously returned iterator is still iterating.<br>
<br>
</div><div class="im"> > Correct me if I'm wrong, but views on dicts are reiterable.<br>
<br>
</div>For the same reason that sequences are: a view is not an iterator, so<br>
every time you iterate it, it gets passed to iter, and you get a new<br>
iterator, which then iterates.<br>
<br>
This is *why* Nick says that "isinstance(x, Iterable) and not<br>
isinstance(x, Iterator)" is the test you want.  I can't speak for Nick<br>
on Steven A's example of an object with a __getitem__ taking a numeric<br>
argument that isn't an Iterable but is iterable, but I think that<br>
falls under "consenting adults" aka "if you're afraid it will hurt,<br>
don't".<br>
<div class="im"><br></div></blockquote><div><br></div><div>I want that test if the documentation will promise that that test is supposed to be right.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">
 > Your second point that the method should be able to cheaply clone<br>
 > an iterator cheaply is precisely what I'd like to achieve with a<br>
 > "Reiterator" class like Antoine's.<br>
<br>
</div>Well, I've kinda convinced myself that it isn't going to be easy to do<br>
that, without changing the type.  The problem is that __next__ is<br>
(abstractly) a closure, and there's no way I know of to copy a<br>
function (copy.copy just returns the function object unchanged).  So<br>
you'd need to expose the hidden state in the closure, and that is a<br>
change of type.<br>
<div class="im"><br>
 > It sounds like you're saying put the items into a list no matter<br>
 > what.<br>
<br>
</div>No, I'm saying if you don't know if you may consume the iterable, you<br>
should convert to iterator, clone the iterator, and iterate the<br>
clone.  But that probably requires a change of type, at which point<br>
you may as well call it "Reiterable".<br>
<br>
<br>
</blockquote></div>okay, so we're on the same page it sounds like.</div></div>