Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7fa82227
Commit
7fa82227
authored
Oct 12, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix links to the __next__ method.
parent
35cbf162
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
60 additions
and
55 deletions
+60
-55
Doc/glossary.rst
Doc/glossary.rst
+1
-1
Doc/library/concurrent.futures.rst
Doc/library/concurrent.futures.rst
+12
-10
Doc/library/dis.rst
Doc/library/dis.rst
+4
-4
Doc/library/exceptions.rst
Doc/library/exceptions.rst
+1
-1
Doc/library/functions.rst
Doc/library/functions.rst
+11
-10
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+5
-4
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+3
-3
Doc/reference/expressions.rst
Doc/reference/expressions.rst
+12
-11
Doc/tutorial/classes.rst
Doc/tutorial/classes.rst
+9
-9
Doc/whatsnew/3.0.rst
Doc/whatsnew/3.0.rst
+2
-2
No files found.
Doc/glossary.rst
View file @
7fa82227
...
...
@@ -354,7 +354,7 @@ Glossary
iterator
An object representing a stream of data. Repeated calls to the iterator's
:meth:`__next__` method (or passing it to the built-in function
:meth:`
~iterator.
__next__` method (or passing it to the built-in function
:func:`next`) return successive items in the stream. When no more data
are available a :exc:`StopIteration` exception is raised instead. At this
point, the iterator object is exhausted and any further calls to its
...
...
Doc/library/concurrent.futures.rst
View file @
7fa82227
...
...
@@ -42,12 +42,13 @@ Executor Objects
Equivalent to ``map(func, *iterables)`` except *func* is executed
asynchronously and several calls to *func* may be made concurrently. The
returned iterator raises a :exc:`TimeoutError` if :meth:`__next__()` is
called and the result isn't available after *timeout* seconds from the
original call to :meth:`Executor.map`. *timeout* can be an int or a
float. If *timeout* is not specified or ``None``, there is no limit to
the wait time. If a call raises an exception, then that exception will
be raised when its value is retrieved from the iterator.
returned iterator raises a :exc:`TimeoutError` if
:meth:`~iterator.__next__` is called and the result isn't available
after *timeout* seconds from the original call to :meth:`Executor.map`.
*timeout* can be an int or a float. If *timeout* is not specified or
``None``, there is no limit to the wait time. If a call raises an
exception, then that exception will be raised when its value is
retrieved from the iterator.
.. method:: shutdown(wait=True)
...
...
@@ -358,10 +359,11 @@ Module Functions
different :class:`Executor` instances) given by *fs* that yields futures as
they complete (finished or were cancelled). Any futures that completed
before :func:`as_completed` is called will be yielded first. The returned
iterator raises a :exc:`TimeoutError` if :meth:`__next__` is called and the
result isn't available after *timeout* seconds from the original call to
:func:`as_completed`. *timeout* can be an int or float. If *timeout* is not
specified or ``None``, there is no limit to the wait time.
iterator raises a :exc:`TimeoutError` if :meth:`~iterator.__next__` is
called and the result isn't available after *timeout* seconds from the
original call to :func:`as_completed`. *timeout* can be an int or float.
If *timeout* is not specified or ``None``, there is no limit to the wait
time.
.. seealso::
...
...
Doc/library/dis.rst
View file @
7fa82227
...
...
@@ -658,10 +658,10 @@ the more significant byte last.
.. opcode:: FOR_ITER (delta)
``TOS`` is an :term:`iterator`. Call its :meth:`
__next__` method. If this
yields a new value, push it on the stack (leaving the iterator below it). If
the iterator indicates it is exhausted ``TOS`` is popped, and the byte cod
e
counter is incremented by *delta*.
``TOS`` is an :term:`iterator`. Call its :meth:`
~iterator.__next__` method.
If this yields a new value, push it on the stack (leaving the iterator below
it). If the iterator indicates it is exhausted ``TOS`` is popped, and th
e
byte code
counter is incremented by *delta*.
.. opcode:: LOAD_GLOBAL (namei)
...
...
Doc/library/exceptions.rst
View file @
7fa82227
...
...
@@ -262,7 +262,7 @@ The following exceptions are the exceptions that are usually raised.
.. exception:: StopIteration
Raised by built-in function :func:`next` and an :term:`iterator`\'s
:meth:`__next__` method to signal that there are no further values.
:meth:`
~iterator.
__next__` method to signal that there are no further values.
.. exception:: SyntaxError
...
...
Doc/library/functions.rst
View file @
7fa82227
...
...
@@ -346,10 +346,10 @@ are always available. They are listed here in alphabetical order.
.. function:: enumerate(iterable, start=0)
Return an enumerate object. *iterable* must be a sequence, an
:term:`iterator`, or some other object which supports iteration.
The
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
tuple containing a count (from *start* which defaults to 0) and the
values obtained from iterating over *iterable*.
:term:`iterator`, or some other object which supports iteration.
The :meth:`~iterator.__next__` method of the iterator returned by
:func:`enumerate` returns a tuple containing a count (from *start* which
defaults to 0) and the
values obtained from iterating over *iterable*.
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
...
...
@@ -681,9 +681,10 @@ are always available. They are listed here in alphabetical order.
starting at ``0``). If it does not support either of those protocols,
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
then *object* must be a callable object. The iterator created in this case
will call *object* with no arguments for each call to its :meth:`__next__`
method; if the value returned is equal to *sentinel*, :exc:`StopIteration`
will be raised, otherwise the value will be returned.
will call *object* with no arguments for each call to its
:meth:`~iterator.__next__` method; if the value returned is equal to
*sentinel*, :exc:`StopIteration` will be raised, otherwise the value will
be returned.
One useful application of the second form of :func:`iter` is to read lines of
a file until a certain line is reached. The following example reads a file
...
...
@@ -781,9 +782,9 @@ are always available. They are listed here in alphabetical order.
.. function:: next(iterator[, default])
Retrieve the next item from the *iterator* by calling its
:meth:`__next__`
method. If *default* is given, it is returned if the iterator is exhausted,
otherwise :exc:`StopIteration` is raised.
Retrieve the next item from the *iterator* by calling its
:meth:`~iterator.__next__` method. If *default* is given, it is returned
if the iterator is exhausted,
otherwise :exc:`StopIteration` is raised.
.. function:: object()
...
...
Doc/library/stdtypes.rst
View file @
7fa82227
...
...
@@ -775,9 +775,9 @@ specific sequence types, dictionaries, and other more specialized forms. The
specific types are not important beyond their implementation of the iterator
protocol.
Once an iterator's :meth:`
__next__` method raises :exc:`StopIteration`, it must
continue to do so on subsequent calls. Implementations that do not obey this
property are deemed broken.
Once an iterator's :meth:`
~iterator.__next__` method raises
:exc:`StopIteration`, it must continue to do so on subsequent calls.
Implementations that do not obey this
property are deemed broken.
.. _generator-types:
...
...
@@ -788,7 +788,8 @@ Generator Types
Python's :term:`generator`\s provide a convenient way to implement the iterator
protocol. If a container object's :meth:`__iter__` method is implemented as a
generator, it will automatically return an iterator object (technically, a
generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods.
generator object) supplying the :meth:`__iter__` and :meth:`~generator.__next__`
methods.
More information about generators can be found in :ref:`the documentation for
the yield expression <yieldexpr>`.
...
...
Doc/reference/datamodel.rst
View file @
7fa82227
...
...
@@ -588,9 +588,9 @@ Callable types
A function or method which uses the :keyword:`yield` statement (see section
:ref:`yield`) is called a :dfn:`generator function`. Such a function, when
called, always returns an iterator object which can be used to execute the
body of the function: calling the iterator's :meth:`
__next__` method will
cause the function to execute until it provides a value using th
e
:keyword:`yield` statement. When the function executes a
body of the function: calling the iterator's :meth:`
iterator__next__`
method will cause the function to execute until it provides a valu
e
using the
:keyword:`yield` statement. When the function executes a
:keyword:`return` statement or falls off the end, a :exc:`StopIteration`
exception is raised and the iterator will have reached the end of the set of
values to be returned.
...
...
Doc/reference/expressions.rst
View file @
7fa82227
...
...
@@ -294,13 +294,13 @@ for comprehensions, except that it is enclosed in parentheses instead of
brackets or curly braces.
Variables used in the generator expression are evaluated lazily when the
:meth:`
__next__` method is called for generator object (in the same fashion as
normal generators). However, the leftmost :keyword:`for` clause is immediately
evaluated, so that an error produced by it can be seen before any other possible
error in the code that handles the generator expression. Subsequent
:keyword:`for` clauses cannot be evaluated immediately since they may depend on
the previous :keyword:`for` loop. For example: ``(x*y for x in range(10) for y
in bar(x))``.
:meth:`
~generator.__next__` method is called for generator object (in the same
fashion as normal generators). However, the leftmost :keyword:`for` clause is
immediately evaluated, so that an error produced by it can be seen before any
other possible error in the code that handles the generator expression.
Subsequent :keyword:`for` clauses cannot be evaluated immediately since they
may depend on the previous :keyword:`for` loop. For example: ``(x*y for x in
range(10) for y
in bar(x))``.
The parentheses can be omitted on calls with only one argument. See section
:ref:`calls` for the detail.
...
...
@@ -371,10 +371,11 @@ is already executing raises a :exc:`ValueError` exception.
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
:keyword:`yield` expression, where the generator is suspended again, and the
value of the :token:`expression_list` is returned to :meth:`next`'s caller.
with a :meth:`~generator.__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`
exception is raised.
...
...
Doc/tutorial/classes.rst
View file @
7fa82227
...
...
@@ -738,11 +738,11 @@ using a :keyword:`for` statement::
This style of access is clear, concise, and convenient. The use of iterators
pervades and unifies Python. Behind the scenes, the :keyword:`for` statement
calls :func:`iter` on the container object. The function returns an iterator
object that defines the method :meth:`
__next__` which accesses elements in the
container one at a time. When there are no more elements, :meth:`__next__`
raises a :exc:`StopIteration` exception which tells the :keyword:`for` loop to
terminate. You can call the :meth:`__next__` method using the :func:`next`
built-in function; this example shows how it all works::
object that defines the method :meth:`
~iterator.__next__` which accesses
elements in the container one at a time. When there are no more elements,
:meth:`__next__` raises a :exc:`StopIteration` exception which tells the
:keyword:`for` loop to terminate. You can call the :meth:`__next__` method
using the :func:`next`
built-in function; this example shows how it all works::
>>> s = 'abc'
>>> it = iter(s)
...
...
@@ -762,8 +762,8 @@ built-in function; this example shows how it all works::
Having seen the mechanics behind the iterator protocol, it is easy to add
iterator behavior to your classes. Define an :meth:`__iter__` method which
returns an object with a :meth:`
__next__` method. If the class define
s
:meth:`__next__`, then :meth:`__iter__` can just return ``self``::
returns an object with a :meth:`
~iterator.__next__` method. If the clas
s
defines
:meth:`__next__`, then :meth:`__iter__` can just return ``self``::
class Reverse:
"""Iterator for looping over a sequence backwards."""
...
...
@@ -820,8 +820,8 @@ easy to create::
Anything that can be done with generators can also be done with class based
iterators as described in the previous section. What makes generators so
compact is that the :meth:`__iter__` and :meth:`
__next__` methods are created
automatically.
compact is that the :meth:`__iter__` and :meth:`
~generator.__next__` methods
a
re created a
utomatically.
Another key feature is that the local variables and execution state are
automatically saved between calls. This made the function easier to write and
...
...
Doc/whatsnew/3.0.rst
View file @
7fa82227
...
...
@@ -771,7 +771,7 @@ Operators And Special Methods
respectively).
* :pep:`3114`: the standard :meth:`next` method has been renamed to
:meth:`__next__`.
:meth:`
~iterator.
__next__`.
* The :meth:`__oct__` and :meth:`__hex__` special methods are removed
-- :func:`oct` and :func:`hex` use :meth:`__index__` now to convert
...
...
@@ -807,7 +807,7 @@ Builtins
To get the old behavior of :func:`input`, use ``eval(input())``.
* A new built-in function :func:`next` was added to call the
:meth:`__next__` method on an object.
:meth:`
~iterator.
__next__` method on an object.
* The :func:`round` function rounding strategy and return type have
changed. Exact halfway cases are now rounded to the nearest even
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment