← Back to DAGDA | Support | Source: https://github.com/python/cpython/commit/01438ed4c22ca150da1cc5c38d83a59b0b6a62a7
Skip to content

Commit 01438ed

Browse files
miss-islingtonrhettinger
authored andcommitted
[3.6] bpo-18558: Clarify glossary entry for "Iterable" (GH-3732) (#3741)
(cherry picked from commit 0bf287b)
1 parent d38caf6 commit 01438ed

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎Doc/glossary.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,10 @@ Glossary
535535
iterables include all sequence types (such as :class:`list`, :class:`str`,
536536
and :class:`tuple`) and some non-sequence types like :class:`dict`,
537537
:term:`file objects <file object>`, and objects of any classes you define
538-
with an :meth:`__iter__` or :meth:`__getitem__` method. Iterables can be
538+
with an :meth:`__iter__` method or with a :meth:`__getitem__` method
539+
that implements :term:`Sequence` semantics.
540+
541+
Iterables can be
539542
used in a :keyword:`for` loop and in many other places where a sequence is
540543
needed (:func:`zip`, :func:`map`, ...). When an iterable object is passed
541544
as an argument to the built-in function :func:`iter`, it returns an

‎Doc/library/collections.abc.rst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ ABC Inherits from Abstract Methods Mixin
107107
.. class:: Iterable
108108

109109
ABC for classes that provide the :meth:`__iter__` method.
110-
See also the definition of :term:`iterable`.
110+
111+
Checking ``isinstance(obj, Iterable)`` detects classes that are registered
112+
as :class:`Iterable` or that have an :meth:`__iter__` method, but it does
113+
not detect classes that iterate with the :meth:`__getitem__` method.
114+
The only reliable way to determine whether an object is :term:`iterable`
115+
is to call ``iter(obj)``.
111116

112117
.. class:: Collection
113118

0 commit comments

Comments
 (0)