Issue 10410: Is iterable a container type? (original) (raw)

Issue10410

Created on 2010-11-13 19:18 by methane, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg121152 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2010-11-13 19:18
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.
msg121166 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-13 23:51
> "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.c?view=markup .
msg121175 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-14 05:27
Removed the incorrect "container" reference. See r86463.
msg121184 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2010-11-14 10:25
>> 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!
History
Date User Action Args
2022-04-11 14:57:08 admin set github: 54619
2010-11-14 10:25:23 methane set messages: +
2010-11-14 05:27:56 rhettinger set status: open -> closedresolution: fixedmessages: +
2010-11-13 23:51:22 rhettinger set priority: normal -> lowmessages: +
2010-11-13 23:41:30 rhettinger set assignee: docs@python -> rhettingernosy: + rhettinger
2010-11-13 19🔞27 methane create