[Python-ideas] Introduce collections.Reiterable
Steven D'Aprano
steve at pearwood.info
Sat Sep 21 06:09:04 CEST 2013
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
More information about the Python-ideas
mailing list