[Python-3000-checkins] r64696 - in python/branches/py3k/Doc: glossary.rst howto/functional.rst reference/expressions.rst

benjamin.peterson python-3000-checkins at python.org
Thu Jul 3 22:28:26 CEST 2008


Author: benjamin.peterson
Date: Thu Jul  3 22:28:26 2008
New Revision: 64696

Log:
remove traces of .next

Modified:
   python/branches/py3k/Doc/glossary.rst
   python/branches/py3k/Doc/howto/functional.rst
   python/branches/py3k/Doc/reference/expressions.rst

Modified: python/branches/py3k/Doc/glossary.rst
==============================================================================
--- python/branches/py3k/Doc/glossary.rst	(original)
+++ python/branches/py3k/Doc/glossary.rst	Thu Jul  3 22:28:26 2008
@@ -168,7 +168,7 @@
       :keyword:`yield` elements back to the caller.  The function execution is
       stopped at the :keyword:`yield` keyword (returning the result) and is
       resumed there when the next element is requested by calling the
-      :meth:`next` method of the returned iterator.
+      :meth:`__next__` method of the returned iterator.
     
       .. index:: single: generator expression
     
@@ -266,11 +266,12 @@
     
    iterator
       An object representing a stream of data.  Repeated calls to the iterator's
-      :meth:`next` method return successive items in the stream.  When no more
-      data is available a :exc:`StopIteration` exception is raised instead.  At
-      this point, the iterator object is exhausted and any further calls to its
-      :meth:`next` method just raise :exc:`StopIteration` again.  Iterators are
-      required to have an :meth:`__iter__` method that returns the iterator
+      :meth:`__next__` (or passing it to the builtin function) :func:`next`
+      method return successive items in the stream.  When no more data is
+      available a :exc:`StopIteration` exception is raised instead.  At this
+      point, the iterator object is exhausted and any further calls to its
+      :meth:`__next__` method just raise :exc:`StopIteration` again.  Iterators
+      are required to have an :meth:`__iter__` method that returns the iterator
       object itself so every iterator is also iterable and may be used in most
       places where other iterables are accepted.  One notable exception is code
       that attempts multiple iteration passes.  A container object (such as a

Modified: python/branches/py3k/Doc/howto/functional.rst
==============================================================================
--- python/branches/py3k/Doc/howto/functional.rst	(original)
+++ python/branches/py3k/Doc/howto/functional.rst	Thu Jul  3 22:28:26 2008
@@ -184,11 +184,11 @@
 
 An iterator is an object representing a stream of data; this object returns the
 data one element at a time.  A Python iterator must support a method called
-``next()`` that takes no arguments and always returns the next element of the
-stream.  If there are no more elements in the stream, ``next()`` must raise the
-``StopIteration`` exception.  Iterators don't have to be finite, though; it's
-perfectly reasonable to write an iterator that produces an infinite stream of
-data.
+``__next__()`` that takes no arguments and always returns the next element of
+the stream.  If there are no more elements in the stream, ``__next__()`` must
+raise the ``StopIteration`` exception.  Iterators don't have to be finite,
+though; it's perfectly reasonable to write an iterator that produces an infinite
+stream of data.
 
 The built-in :func:`iter` function takes an arbitrary object and tries to return
 an iterator that will return the object's contents or elements, raising
@@ -203,13 +203,13 @@
     >>> it = iter(L)
     >>> it
     <...iterator object at ...>
-    >>> it.next()
+    >>> it.__next__()
     1
-    >>> it.next()
+    >>> next(it)
     2
-    >>> it.next()
+    >>> next(it)
     3
-    >>> it.next()
+    >>> next(it)
     Traceback (most recent call last):
       File "<stdin>", line 1, in ?
     StopIteration
@@ -467,20 +467,20 @@
 ``return`` statement.  The big difference between ``yield`` and a ``return``
 statement is that on reaching a ``yield`` the generator's state of execution is
 suspended and local variables are preserved.  On the next call to the
-generator's ``.next()`` method, the function will resume executing.
+generator's ``.__next__()`` method, the function will resume executing.
 
 Here's a sample usage of the ``generate_ints()`` generator:
 
     >>> gen = generate_ints(3)
     >>> gen
     <generator object at ...>
-    >>> gen.next()
+    >>> next(gen)
     0
-    >>> gen.next()
+    >>> next(gen)
     1
-    >>> gen.next()
+    >>> next(gen)
     2
-    >>> gen.next()
+    >>> next(gen)
     Traceback (most recent call last):
       File "stdin", line 1, in ?
       File "stdin", line 2, in generate_ints
@@ -500,7 +500,7 @@
 You could achieve the effect of generators manually by writing your own class
 and storing all the local variables of the generator as instance variables.  For
 example, returning a list of integers could be done by setting ``self.count`` to
-0, and having the ``next()`` method increment ``self.count`` and return it.
+0, and having the ``__next__()`` method increment ``self.count`` and return it.
 However, for a moderately complicated generator, writing a corresponding class
 can be much messier.
 
@@ -555,7 +555,7 @@
 
 Values are sent into a generator by calling its ``send(value)`` method.  This
 method resumes the generator's code and the ``yield`` expression returns the
-specified value.  If the regular ``next()`` method is called, the ``yield``
+specified value.  If the regular ``__next__()`` method is called, the ``yield``
 returns ``None``.
 
 Here's a simple counter that increments by 1 and allows changing the value of
@@ -576,15 +576,15 @@
 And here's an example of changing the counter:
 
     >>> it = counter(10)
-    >>> it.next()
+    >>> next(it)
     0
-    >>> it.next()
+    >>> next(it)
     1
     >>> it.send(8)
     8
-    >>> it.next()
+    >>> next(it)
     9
-    >>> it.next()
+    >>> next(it)
     Traceback (most recent call last):
       File ``t.py'', line 15, in ?
         it.next()

Modified: python/branches/py3k/Doc/reference/expressions.rst
==============================================================================
--- python/branches/py3k/Doc/reference/expressions.rst	(original)
+++ python/branches/py3k/Doc/reference/expressions.rst	Thu Jul  3 22:28:26 2008
@@ -375,8 +375,8 @@
 
    Starts the execution of a generator function or resumes it at the last
    executed :keyword:`yield` expression.  When a generator function is resumed
-   with a :meth:`next` method, the current :keyword:`yield` expression always
-   evaluates to :const:`None`.  The execution then continues to the next
+   with a :meth:`__next__` method, the current :keyword:`yield` expression
+   always evaluates to :const:`None`.  The execution then continues to the next
    :keyword:`yield` expression, where the generator is suspended again, and the
    value of the :token:`expression_list` is returned to :meth:`next`'s caller.
    If the generator exits without yielding another value, a :exc:`StopIteration`


More information about the Python-3000-checkins mailing list