[Python-ideas] Introduce collections.Reiterable

Nick Coghlan ncoghlan at gmail.com
Sun Sep 22 16:22:19 CEST 2013

On 22 September 2013 22:21, Steven D'Aprano <steve at pearwood.info> wrote:
>> This
>> means that there are a small number of legacy cases where
>> "isinstance(c, collections.abc.Iterable)" can be False, while calling
>> "iter(c)" would still give you a working iterator.
> I'm sure you realise this, but just to be clear, there's no need to
> explicitly call iter(c). More to my point, you can simply iterate over c
> using a for-loop:
> for element in c:
>     ...
> thus proving that c is iterable, since you've just iterated over it.

It's still the implicit call to iter() inside the for loop that
converts the iterable to an iterator though. And these are exactly the
cases that I am saying *deliberately* fail the more formal check
instituted in PEP 3119. The __getitem__ fallback is a backwards
compatibility hack, not part of the formal definition of an iterable.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list