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

Skip to content

Commit e7c78b2

Browse files
committed
remove traces of .next
1 parent 69164c7 commit e7c78b2

3 files changed

Lines changed: 29 additions & 28 deletions

File tree

Doc/glossary.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Glossary
168168
:keyword:`yield` elements back to the caller. The function execution is
169169
stopped at the :keyword:`yield` keyword (returning the result) and is
170170
resumed there when the next element is requested by calling the
171-
:meth:`next` method of the returned iterator.
171+
:meth:`__next__` method of the returned iterator.
172172

173173
.. index:: single: generator expression
174174

@@ -266,11 +266,12 @@ Glossary
266266

267267
iterator
268268
An object representing a stream of data. Repeated calls to the iterator's
269-
:meth:`next` method return successive items in the stream. When no more
270-
data is available a :exc:`StopIteration` exception is raised instead. At
271-
this point, the iterator object is exhausted and any further calls to its
272-
:meth:`next` method just raise :exc:`StopIteration` again. Iterators are
273-
required to have an :meth:`__iter__` method that returns the iterator
269+
:meth:`__next__` (or passing it to the builtin function) :func:`next`
270+
method return successive items in the stream. When no more data is
271+
available a :exc:`StopIteration` exception is raised instead. At this
272+
point, the iterator object is exhausted and any further calls to its
273+
:meth:`__next__` method just raise :exc:`StopIteration` again. Iterators
274+
are required to have an :meth:`__iter__` method that returns the iterator
274275
object itself so every iterator is also iterable and may be used in most
275276
places where other iterables are accepted. One notable exception is code
276277
that attempts multiple iteration passes. A container object (such as a

Doc/howto/functional.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ foundation for writing functional-style programs: iterators.
184184

185185
An iterator is an object representing a stream of data; this object returns the
186186
data one element at a time. A Python iterator must support a method called
187-
``next()`` that takes no arguments and always returns the next element of the
188-
stream. If there are no more elements in the stream, ``next()`` must raise the
189-
``StopIteration`` exception. Iterators don't have to be finite, though; it's
190-
perfectly reasonable to write an iterator that produces an infinite stream of
191-
data.
187+
``__next__()`` that takes no arguments and always returns the next element of
188+
the stream. If there are no more elements in the stream, ``__next__()`` must
189+
raise the ``StopIteration`` exception. Iterators don't have to be finite,
190+
though; it's perfectly reasonable to write an iterator that produces an infinite
191+
stream of data.
192192

193193
The built-in :func:`iter` function takes an arbitrary object and tries to return
194194
an iterator that will return the object's contents or elements, raising
@@ -203,13 +203,13 @@ You can experiment with the iteration interface manually:
203203
>>> it = iter(L)
204204
>>> it
205205
<...iterator object at ...>
206-
>>> it.next()
206+
>>> it.__next__()
207207
1
208-
>>> it.next()
208+
>>> next(it)
209209
2
210-
>>> it.next()
210+
>>> next(it)
211211
3
212-
>>> it.next()
212+
>>> next(it)
213213
Traceback (most recent call last):
214214
File "<stdin>", line 1, in ?
215215
StopIteration
@@ -467,20 +467,20 @@ the ``yield`` expression, the generator outputs the value of ``i``, similar to a
467467
``return`` statement. The big difference between ``yield`` and a ``return``
468468
statement is that on reaching a ``yield`` the generator's state of execution is
469469
suspended and local variables are preserved. On the next call to the
470-
generator's ``.next()`` method, the function will resume executing.
470+
generator's ``.__next__()`` method, the function will resume executing.
471471

472472
Here's a sample usage of the ``generate_ints()`` generator:
473473

474474
>>> gen = generate_ints(3)
475475
>>> gen
476476
<generator object at ...>
477-
>>> gen.next()
477+
>>> next(gen)
478478
0
479-
>>> gen.next()
479+
>>> next(gen)
480480
1
481-
>>> gen.next()
481+
>>> next(gen)
482482
2
483-
>>> gen.next()
483+
>>> next(gen)
484484
Traceback (most recent call last):
485485
File "stdin", line 1, in ?
486486
File "stdin", line 2, in generate_ints
@@ -500,7 +500,7 @@ the bottom of the function.
500500
You could achieve the effect of generators manually by writing your own class
501501
and storing all the local variables of the generator as instance variables. For
502502
example, returning a list of integers could be done by setting ``self.count`` to
503-
0, and having the ``next()`` method increment ``self.count`` and return it.
503+
0, and having the ``__next__()`` method increment ``self.count`` and return it.
504504
However, for a moderately complicated generator, writing a corresponding class
505505
can be much messier.
506506

@@ -555,7 +555,7 @@ but have to use parentheses when there's an operation, as in ``val = (yield i)
555555

556556
Values are sent into a generator by calling its ``send(value)`` method. This
557557
method resumes the generator's code and the ``yield`` expression returns the
558-
specified value. If the regular ``next()`` method is called, the ``yield``
558+
specified value. If the regular ``__next__()`` method is called, the ``yield``
559559
returns ``None``.
560560

561561
Here's a simple counter that increments by 1 and allows changing the value of
@@ -576,15 +576,15 @@ the internal counter.
576576
And here's an example of changing the counter:
577577

578578
>>> it = counter(10)
579-
>>> it.next()
579+
>>> next(it)
580580
0
581-
>>> it.next()
581+
>>> next(it)
582582
1
583583
>>> it.send(8)
584584
8
585-
>>> it.next()
585+
>>> next(it)
586586
9
587-
>>> it.next()
587+
>>> next(it)
588588
Traceback (most recent call last):
589589
File ``t.py'', line 15, in ?
590590
it.next()

Doc/reference/expressions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ generator function:
375375

376376
Starts the execution of a generator function or resumes it at the last
377377
executed :keyword:`yield` expression. When a generator function is resumed
378-
with a :meth:`next` method, the current :keyword:`yield` expression always
379-
evaluates to :const:`None`. The execution then continues to the next
378+
with a :meth:`__next__` method, the current :keyword:`yield` expression
379+
always evaluates to :const:`None`. The execution then continues to the next
380380
:keyword:`yield` expression, where the generator is suspended again, and the
381381
value of the :token:`expression_list` is returned to :meth:`next`'s caller.
382382
If the generator exits without yielding another value, a :exc:`StopIteration`

0 commit comments

Comments
 (0)