[Python-ideas] Introduce collections.Reiterable
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.
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
> 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.
> Python-ideas mailing list
> Python-ideas at python.org
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> 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...
More information about the Python-ideas