[Python-ideas] Introduce collections.Reiterable
Steven D'Aprano
steve at pearwood.info
Sat Sep 21 10:04:06 CEST 2013
On Sat, Sep 21, 2013 at 12:23:54AM -0400, Neil Girdhar wrote:
> I appreciate the discussion illuminating various aspects of this I hadn't
> considered. Finally, what I think I want is for
> * all sequences
> * all views
> * numpy arrays
> to answer yes to reiterable, and
> * all generators
> to answer no to reiterable.
Which brings us full circle to:
if isinstance(obj, Iterable) and not isinstance(obj, Iterator):
print("Is re-iterable")
else:
print("Is not re-iterable")
which I believe satisfies your requirement. Can you show any standard,
non-pathological type where this test fails to give the correct answer?
If not, what exactly is the problem with just using that test?
As far as I am concerned, not every one-line test needs an ABC.
--
Steven
More information about the Python-ideas
mailing list