Author r.david.murray
Recipients Zero, docs@python, r.david.murray
Date 2013-07-26.01:25:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374801940.5.0.979589568485.issue18558@psf.upfronthosting.co.za>
In-reply-to
Content
The definition of an Iterable is a class that defines an __iter__  method.  Your class does not, so the behavior you site is correct.

The glossary entry for 'iterable' could use a little clarification.  A class that defines __getitem__ is an iterable if and only if it returns results when passed integers.  Since the documentation for Iterable references that glossary entry, it should probably also be explicit that defining __getitem__ does not (because of the forgoing limitation) cause isinstance(x, Iterable) to be True.  For a class that does not define __iter__, you must explicitly register it with Iterable.

To see why this must be so, consider this:

  >>> y = IsIterable({'a': 'b', 'c': 'd'})
  >>> [x for x in y]
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 1, in <listcomp>
    File "<stdin>", line 5, in __getitem__
  KeyError: 0
History
Date User Action Args
2013-07-26 01:25:40r.david.murraysetrecipients: + r.david.murray, Zero, docs@python
2013-07-26 01:25:40r.david.murraysetmessageid: <1374801940.5.0.979589568485.issue18558@psf.upfronthosting.co.za>
2013-07-26 01:25:40r.david.murraylinkissue18558 messages
2013-07-26 01:25:39r.david.murraycreate