[Python-ideas] Introduce collections.Reiterable

Neil Girdhar mistersheik at gmail.com
Sat Sep 21 06:16:41 CEST 2013


You're right that you should go ahead and use something however you want
to.  However, there are plenty of times where you can't do that, e.g., you
want to know if something is callable before calling it, and similarly if
something is reiterable before iterating it and exhausting.  That is the
purpose of collections.abc, and that's what I thought we were discussing.
 Could you make mistakes trying to look ahead like this?  Sure.  An object
could appear callable only to raise NotImplementedError on calling it.
 Looking ahead does not have to be foolproof.  This is Python, and of
course (almost) *any test* can be fooled.  That doesn't just go for
reiterability, it goes for callability as well.

Best,
Neil


On Sat, Sep 21, 2013 at 12:09 AM, Steven D'Aprano <steve at pearwood.info>wrote:

> On Sat, Sep 21, 2013 at 12:00:14AM -0400, Neil Girdhar wrote:
> > If someone allows their class to fail the standardized test for
> > Iterable/Reiterable/Sequence, that class doesn't deserve to be treated as
> > one.  (Anyone can register their class as a subclass of the ABCs, or more
> > simply inherit from one.)
>
> This is Python, and duck-typing rules, not Java-like type checking. If
> you want a language with strict type checking designed by theorists, try
> Haskell.
>
> The ultimate test in Python of whether something is iterable or not is
> to try iterating over it, and see if it succeeds or not. If it iterates
> like a duck, that's good enough to be treated as a duck.
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/OumiLGDwRWA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130921/d3ea426c/attachment-0001.html>


More information about the Python-ideas mailing list