R. David Murray added the comment: 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 ---------- assignee: -> docs@python components: +Documentation -Library (Lib) nosy: +docs@python, r.david.murray stage: -> needs patch title: Iterables not detected correctly -> Iterable glossary entry needs clarification versions: +Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18558> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com