<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Sep 21, 2013 at 2:25 AM, 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">Neil Girdhar writes:<br>
<br>
 > You're right that you should go ahead and use something however you<br>
 > want to.  However, there are plenty of times where you can't do that,<br>
 > e.g., you want to know if something is callable before calling it,<br>
 > and similarly if something is reiterable before iterating it and<br>
 > exhausting.  That is the purpose of collections.abc,<br>
<br>
</div>I don't think so.  It's documented that way:<br>
<br>
    This module provides abstract base classes that can be used to<br>
    test whether a class provides a particular interface; for example,<br>
    whether it is hashable or whether it is a mapping.<br>
<br>
But I wouldn't do explicit testing with isinstance, but rather use<br>
implicit assertions (at instantiation time) by deriving from the ABC.<br>
I don't see how Reiterable could be adapted to this style of<br>
programming because the API of iterables is basically fixed (support<br>
__iter__ or __getitem__).<br></blockquote><div><br></div><div>Wouldn't you need to define a new ABC to do this?</div><div><br></div><div>Here's one possibility with Tim's iterable and not iterator:</div><div>

<br></div><div>class Reiterable(collections.Iterable,</div><div>                 metaclass=collections.abc.ABCMeta):</div><div>    @classmethod</div><div>    def __subclasshook__(cls, subclass):</div><div>        if (collections.Iterable.__subclasshook__(subclass)</div>

<div>            and not issubclass(subclass, collections.Iterator)):</div><div>            return True</div><div>        return NotImplemented</div><div><br></div><div>for obj in [list(), tuple(), dict(), set(), range(4),</div>

<div>            (x * x for x in range(4))]:</div><div>    print(type(obj),</div><div>          isinstance(obj, Reiterable))</div><div><br></div><div>Another possibility would be to explicitly register Views and so on using</div>

<div><br></div><div>Reiterable.register(...)</div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div class="im"><br>
 > and that's what I thought we were discussing.<br>
<br>
</div>You were, I agree.  But you proposed a new API, which pretty well<br>
guarantees many discussants will take a more global view, like "do the<br>
use cases justify this addition?"<br></blockquote><div><br></div><div>It's a good point.  I think if I'm the only with this problem, then the answer is clearly no.  I will just cast to list and so what if it's a little bit slower in some cases. How could I know that I was the only one with this problem?</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Another such question is "what exactly is the specification?"  Tim<br>
Delany, for example, AIUI doesn't have a problem with saying that any<br>
iterable is reiterable, because it won't raise an exception if the<br>
program iterates it after exhaustion.  It simply does nothing, but in<br>
some cases that's perfectly acceptable.  I know you disagree, and I<br>
don't think that's a useful definition.  Still it demonstrates the<br>
wide range of opinions on what "reiterable" can or should guarantee.<br>
</blockquote></div><br></div><div class="gmail_extra">Yes, agreed that there are a wide range of reasonable opinions.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Best,</div><div class="gmail_extra"><br>

Neil</div></div>