[Python-ideas] Introduce collections.Reiterable

Stephen J. Turnbull stephen at xemacs.org
Tue Sep 24 03:04:03 CEST 2013

Neil Girdhar writes:

 > If infinite sequences are so common, it might be better to add a
 > collections.abc for them.

I suspect this falls under the "not every 3-line function" clause,
because it would really require a PEP to get right (changes to
builtins like list and dict would be needed, IIUC).

Just inherit from Sequence and add a __len__ which returns a unique
object (probably could be None, actually), and check for that private
protocol yourself.

P.S.  Please don't post via Google Groups.  It results in spam for
those of us who don't subscribe to the Google Group.

More information about the Python-ideas mailing list