Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0bf287b

Browse files
authored
bpo-18558: Clarify glossary entry for "Iterable" (#3732)
1 parent b1d1c42 commit 0bf287b

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)