[issue10410] Is iterable a container type?

New submission from INADA Naoki <songofacandy@gmail.com>: In http://docs.python.org/release/2.6.6/glossary.html, "iterable" is described as "A container object capable of returning its members one at a time." Is it correct? Is stream object like file a container type? Container ABC requires only "__contains__" abstract method. I think file is iterable but is not container. Likewise, "and objects of any classes you define with an __iter__() or __getitem__() method." is wrong because __getitem__ method is not relate to iterable. ---------- assignee: docs@python components: Documentation messages: 121152 nosy: docs@python, naoki priority: normal severity: normal status: open title: Is iterable a container type? versions: Python 2.6, Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10410> _______________________________________

Changes by Raymond Hettinger <rhettinger@users.sourceforge.net>: ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10410> _______________________________________

Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment:
"iterable" is described as "A container object capable of returning its members one at a time."
That wording is confusing. I'll fix it.
Likewise, "and objects of any classes you define with an __iter__() or __getitem__() method." is wrong because __getitem__ method is not relate to iterable
That wording is correct. Sequences are automatically iterable even if they don't define __iter__. For example:
class A: ... def __getitem__(self, i): ... if i > 10: ... raise IndexError(i) ... return i * 100
list(A()) [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000]
If you're curious, the details are in the PyObject_GetIter() function in http://svn.python.org/view/python/branches/release27-maint/Objects/abstract.... . ---------- priority: normal -> low _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10410> _______________________________________

INADA Naoki <songofacandy@gmail.com> added the comment:
Likewise, "and objects of any classes you define with an __iter__() or __getitem__() method." is wrong because __getitem__ method is not relate to iterable
That wording is correct. Sequences are automatically iterable even if they don't define __iter__. For example:
Wow, thank you! ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10410> _______________________________________

Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment: Removed the incorrect "container" reference. See r86463. ---------- resolution: -> fixed status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10410> _______________________________________
participants (2)
-
INADA Naoki
-
Raymond Hettinger