[Python-ideas] Introduce collections.Reiterable

Raymond Hettinger raymond.hettinger at gmail.com
Sat Sep 21 02:34:22 CEST 2013


On Sep 20, 2013, at 4:59 PM, Terry Reedy <tjreedy at udel.edu> wrote:

>>> . The glossary might say that the older __getitem__ protocol is
>>> semi-deprecated (it is no longer used directly) but is adapted for
>>> back compatibility.
>> 
>> It is NOT deprecated.
> 
> And I did not suggest that is was. It is, however, not fully supported in that collections. Iterable does not recognize __getitem__ iterables and the same will be true of code that uses Iterable.


The collections ABCs are all just a subset of things real collections do.   For example, there is no slicing support.  This was intentional.

To some degree, the only test of whether something is iterable is to call iter() on it and see what happens.  With Python's __getattr__ method, the only way to test for many behaviors is to attempt to call invoke them to see what happens.  That is why hasattr() has to invoke getattr().


Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130920/a46f2633/attachment.html>


More information about the Python-ideas mailing list