Message193724
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 |
|
Date |
User |
Action |
Args |
2013-07-26 01:25:40 | r.david.murray | set | recipients:
+ r.david.murray, Zero, docs@python |
2013-07-26 01:25:40 | r.david.murray | set | messageid: <1374801940.5.0.979589568485.issue18558@psf.upfronthosting.co.za> |
2013-07-26 01:25:40 | r.david.murray | link | issue18558 messages |
2013-07-26 01:25:39 | r.david.murray | create | |
|