mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-35506: Remove redundant and incorrect links from keywords. (GH-11174)
This commit is contained in:
parent
82d73554e4
commit
2b57c43f21
45 changed files with 240 additions and 242 deletions
|
@ -78,11 +78,11 @@ on a separate line for clarity.
|
|||
.. _elif:
|
||||
.. _else:
|
||||
|
||||
The :keyword:`if` statement
|
||||
===========================
|
||||
The :keyword:`!if` statement
|
||||
============================
|
||||
|
||||
.. index::
|
||||
statement: if
|
||||
! statement: if
|
||||
keyword: elif
|
||||
keyword: else
|
||||
single: : (colon); compound statement
|
||||
|
@ -103,14 +103,13 @@ false, the suite of the :keyword:`else` clause, if present, is executed.
|
|||
|
||||
.. _while:
|
||||
|
||||
The :keyword:`while` statement
|
||||
==============================
|
||||
The :keyword:`!while` statement
|
||||
===============================
|
||||
|
||||
.. index::
|
||||
statement: while
|
||||
! statement: while
|
||||
keyword: else
|
||||
pair: loop; statement
|
||||
keyword: else
|
||||
single: : (colon); compound statement
|
||||
|
||||
The :keyword:`while` statement is used for repeated execution as long as an
|
||||
|
@ -122,7 +121,7 @@ expression is true:
|
|||
|
||||
This repeatedly tests the expression and, if it is true, executes the first
|
||||
suite; if the expression is false (which may be the first time it is tested) the
|
||||
suite of the :keyword:`else` clause, if present, is executed and the loop
|
||||
suite of the :keyword:`!else` clause, if present, is executed and the loop
|
||||
terminates.
|
||||
|
||||
.. index::
|
||||
|
@ -130,25 +129,22 @@ terminates.
|
|||
statement: continue
|
||||
|
||||
A :keyword:`break` statement executed in the first suite terminates the loop
|
||||
without executing the :keyword:`else` clause's suite. A :keyword:`continue`
|
||||
without executing the :keyword:`!else` clause's suite. A :keyword:`continue`
|
||||
statement executed in the first suite skips the rest of the suite and goes back
|
||||
to testing the expression.
|
||||
|
||||
|
||||
.. _for:
|
||||
|
||||
The :keyword:`for` statement
|
||||
============================
|
||||
The :keyword:`!for` statement
|
||||
=============================
|
||||
|
||||
.. index::
|
||||
statement: for
|
||||
! statement: for
|
||||
keyword: in
|
||||
keyword: else
|
||||
pair: target; list
|
||||
pair: loop; statement
|
||||
keyword: in
|
||||
keyword: else
|
||||
pair: target; list
|
||||
object: sequence
|
||||
single: : (colon); compound statement
|
||||
|
||||
|
@ -166,16 +162,16 @@ by the iterator. Each item in turn is assigned to the target list using the
|
|||
standard rules for assignments (see :ref:`assignment`), and then the suite is
|
||||
executed. When the items are exhausted (which is immediately when the sequence
|
||||
is empty or an iterator raises a :exc:`StopIteration` exception), the suite in
|
||||
the :keyword:`else` clause, if present, is executed, and the loop terminates.
|
||||
the :keyword:`!else` clause, if present, is executed, and the loop terminates.
|
||||
|
||||
.. index::
|
||||
statement: break
|
||||
statement: continue
|
||||
|
||||
A :keyword:`break` statement executed in the first suite terminates the loop
|
||||
without executing the :keyword:`else` clause's suite. A :keyword:`continue`
|
||||
without executing the :keyword:`!else` clause's suite. A :keyword:`continue`
|
||||
statement executed in the first suite skips the rest of the suite and continues
|
||||
with the next item, or with the :keyword:`else` clause if there is no next
|
||||
with the next item, or with the :keyword:`!else` clause if there is no next
|
||||
item.
|
||||
|
||||
The for-loop makes assignments to the variables in the target list.
|
||||
|
@ -224,11 +220,11 @@ returns the list ``[0, 1, 2]``.
|
|||
.. _except:
|
||||
.. _finally:
|
||||
|
||||
The :keyword:`try` statement
|
||||
============================
|
||||
The :keyword:`!try` statement
|
||||
=============================
|
||||
|
||||
.. index::
|
||||
statement: try
|
||||
! statement: try
|
||||
keyword: except
|
||||
keyword: finally
|
||||
keyword: else
|
||||
|
@ -250,7 +246,7 @@ for a group of statements:
|
|||
|
||||
The :keyword:`except` clause(s) specify one or more exception handlers. When no
|
||||
exception occurs in the :keyword:`try` clause, no exception handler is executed.
|
||||
When an exception occurs in the :keyword:`try` suite, a search for an exception
|
||||
When an exception occurs in the :keyword:`!try` suite, a search for an exception
|
||||
handler is started. This search inspects the except clauses in turn until one
|
||||
is found that matches the exception. An expression-less except clause, if
|
||||
present, must be last; it matches any exception. For an except clause with an
|
||||
|
@ -270,7 +266,7 @@ as if the entire :keyword:`try` statement raised the exception).
|
|||
.. index:: single: as; except clause
|
||||
|
||||
When a matching except clause is found, the exception is assigned to the target
|
||||
specified after the :keyword:`as` keyword in that except clause, if present, and
|
||||
specified after the :keyword:`!as` keyword in that except clause, if present, and
|
||||
the except clause's suite is executed. All except clauses must have an
|
||||
executable block. When the end of this block is reached, execution continues
|
||||
normally after the entire try statement. (This means that if two nested
|
||||
|
@ -314,22 +310,22 @@ from a function that handled an exception.
|
|||
statement: break
|
||||
statement: continue
|
||||
|
||||
The optional :keyword:`else` clause is executed if the control flow leaves the
|
||||
The optional :keyword:`!else` clause is executed if the control flow leaves the
|
||||
:keyword:`try` suite, no exception was raised, and no :keyword:`return`,
|
||||
:keyword:`continue`, or :keyword:`break` statement was executed. Exceptions in
|
||||
the :keyword:`else` clause are not handled by the preceding :keyword:`except`
|
||||
the :keyword:`!else` clause are not handled by the preceding :keyword:`except`
|
||||
clauses.
|
||||
|
||||
.. index:: keyword: finally
|
||||
|
||||
If :keyword:`finally` is present, it specifies a 'cleanup' handler. The
|
||||
:keyword:`try` clause is executed, including any :keyword:`except` and
|
||||
:keyword:`else` clauses. If an exception occurs in any of the clauses and is
|
||||
not handled, the exception is temporarily saved. The :keyword:`finally` clause
|
||||
:keyword:`!else` clauses. If an exception occurs in any of the clauses and is
|
||||
not handled, the exception is temporarily saved. The :keyword:`!finally` clause
|
||||
is executed. If there is a saved exception it is re-raised at the end of the
|
||||
:keyword:`finally` clause. If the :keyword:`finally` clause raises another
|
||||
:keyword:`!finally` clause. If the :keyword:`!finally` clause raises another
|
||||
exception, the saved exception is set as the context of the new exception.
|
||||
If the :keyword:`finally` clause executes a :keyword:`return`, :keyword:`break`
|
||||
If the :keyword:`!finally` clause executes a :keyword:`return`, :keyword:`break`
|
||||
or :keyword:`continue` statement, the saved exception is discarded::
|
||||
|
||||
>>> def f():
|
||||
|
@ -350,12 +346,12 @@ the :keyword:`finally` clause.
|
|||
statement: continue
|
||||
|
||||
When a :keyword:`return`, :keyword:`break` or :keyword:`continue` statement is
|
||||
executed in the :keyword:`try` suite of a :keyword:`try`...\ :keyword:`finally`
|
||||
executed in the :keyword:`try` suite of a :keyword:`!try`...\ :keyword:`!finally`
|
||||
statement, the :keyword:`finally` clause is also executed 'on the way out.'
|
||||
|
||||
The return value of a function is determined by the last :keyword:`return`
|
||||
statement executed. Since the :keyword:`finally` clause always executes, a
|
||||
:keyword:`return` statement executed in the :keyword:`finally` clause will
|
||||
:keyword:`!return` statement executed in the :keyword:`!finally` clause will
|
||||
always be the last one executed::
|
||||
|
||||
>>> def foo():
|
||||
|
@ -379,11 +375,11 @@ may be found in section :ref:`raise`.
|
|||
.. _with:
|
||||
.. _as:
|
||||
|
||||
The :keyword:`with` statement
|
||||
=============================
|
||||
The :keyword:`!with` statement
|
||||
==============================
|
||||
|
||||
.. index::
|
||||
statement: with
|
||||
! statement: with
|
||||
keyword: as
|
||||
single: as; with statement
|
||||
single: , (comma); with statement
|
||||
|
@ -595,7 +591,7 @@ name), for immediate use in expressions. This uses lambda expressions, describe
|
|||
section :ref:`lambda`. Note that the lambda expression is merely a shorthand for a
|
||||
simplified function definition; a function defined in a ":keyword:`def`"
|
||||
statement can be passed around or assigned to another name just like a function
|
||||
defined by a lambda expression. The ":keyword:`def`" form is actually more powerful
|
||||
defined by a lambda expression. The ":keyword:`!def`" form is actually more powerful
|
||||
since it allows the execution of multiple statements and annotations.
|
||||
|
||||
**Programmer's note:** Functions are first-class objects. A "``def``" statement
|
||||
|
@ -758,8 +754,8 @@ An example of a coroutine function::
|
|||
.. index:: statement: async for
|
||||
.. _`async for`:
|
||||
|
||||
The :keyword:`async for` statement
|
||||
----------------------------------
|
||||
The :keyword:`!async for` statement
|
||||
-----------------------------------
|
||||
|
||||
.. productionlist::
|
||||
async_for_stmt: "async" `for_stmt`
|
||||
|
@ -802,8 +798,8 @@ body of a coroutine function.
|
|||
.. index:: statement: async with
|
||||
.. _`async with`:
|
||||
|
||||
The :keyword:`async with` statement
|
||||
-----------------------------------
|
||||
The :keyword:`!async with` statement
|
||||
------------------------------------
|
||||
|
||||
.. productionlist::
|
||||
async_with_stmt: "async" `with_stmt`
|
||||
|
|
|
@ -620,7 +620,7 @@ Callable types
|
|||
called, always returns an iterator object which can be used to execute the
|
||||
body of the function: calling the iterator's :meth:`iterator.__next__`
|
||||
method will cause the function to execute until it provides a value
|
||||
using the :keyword:`yield` statement. When the function executes a
|
||||
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.
|
||||
|
@ -700,7 +700,7 @@ Modules
|
|||
|
||||
Modules are a basic organizational unit of Python code, and are created by
|
||||
the :ref:`import system <importsystem>` as invoked either by the
|
||||
:keyword:`import` statement (see :keyword:`import`), or by calling
|
||||
:keyword:`import` statement, or by calling
|
||||
functions such as :func:`importlib.import_module` and built-in
|
||||
:func:`__import__`. A module object has a namespace implemented by a
|
||||
dictionary object (this is the dictionary referenced by the ``__globals__``
|
||||
|
@ -2423,7 +2423,7 @@ A :dfn:`context manager` is an object that defines the runtime context to be
|
|||
established when executing a :keyword:`with` statement. The context manager
|
||||
handles the entry into, and the exit from, the desired runtime context for the
|
||||
execution of the block of code. Context managers are normally invoked using the
|
||||
:keyword:`with` statement (described in section :ref:`with`), but can also be
|
||||
:keyword:`!with` statement (described in section :ref:`with`), but can also be
|
||||
used by directly invoking their methods.
|
||||
|
||||
.. index::
|
||||
|
@ -2440,7 +2440,7 @@ For more information on context managers, see :ref:`typecontextmanager`.
|
|||
|
||||
Enter the runtime context related to this object. The :keyword:`with` statement
|
||||
will bind this method's return value to the target(s) specified in the
|
||||
:keyword:`as` clause of the statement, if any.
|
||||
:keyword:`!as` clause of the statement, if any.
|
||||
|
||||
|
||||
.. method:: object.__exit__(self, exc_type, exc_value, traceback)
|
||||
|
|
|
@ -58,8 +58,8 @@ The following constructs bind names: formal parameters to functions,
|
|||
:keyword:`import` statements, class and function definitions (these bind the
|
||||
class or function name in the defining block), and targets that are identifiers
|
||||
if occurring in an assignment, :keyword:`for` loop header, or after
|
||||
:keyword:`as` in a :keyword:`with` statement or :keyword:`except` clause.
|
||||
The :keyword:`import` statement
|
||||
:keyword:`!as` in a :keyword:`with` statement or :keyword:`except` clause.
|
||||
The :keyword:`!import` statement
|
||||
of the form ``from ... import *`` binds all names defined in the imported
|
||||
module, except those beginning with an underscore. This form may only be used
|
||||
at the module level.
|
||||
|
@ -123,7 +123,7 @@ namespace. Names are resolved in the top-level namespace by searching the
|
|||
global namespace, i.e. the namespace of the module containing the code block,
|
||||
and the builtins namespace, the namespace of the module :mod:`builtins`. The
|
||||
global namespace is searched first. If the name is not found there, the
|
||||
builtins namespace is searched. The :keyword:`global` statement must precede
|
||||
builtins namespace is searched. The :keyword:`!global` statement must precede
|
||||
all uses of the name.
|
||||
|
||||
The :keyword:`global` statement has the same scope as a name binding operation
|
||||
|
|
|
@ -185,20 +185,20 @@ Common syntax elements for comprehensions are:
|
|||
comp_if: "if" `expression_nocond` [`comp_iter`]
|
||||
|
||||
The comprehension consists of a single expression followed by at least one
|
||||
:keyword:`for` clause and zero or more :keyword:`for` or :keyword:`if` clauses.
|
||||
:keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` clauses.
|
||||
In this case, the elements of the new container are those that would be produced
|
||||
by considering each of the :keyword:`for` or :keyword:`if` clauses a block,
|
||||
by considering each of the :keyword:`!for` or :keyword:`!if` clauses a block,
|
||||
nesting from left to right, and evaluating the expression to produce an element
|
||||
each time the innermost block is reached.
|
||||
|
||||
However, aside from the iterable expression in the leftmost :keyword:`for` clause,
|
||||
However, aside from the iterable expression in the leftmost :keyword:`!for` clause,
|
||||
the comprehension is executed in a separate implicitly nested scope. This ensures
|
||||
that names assigned to in the target list don't "leak" into the enclosing scope.
|
||||
|
||||
The iterable expression in the leftmost :keyword:`for` clause is evaluated
|
||||
The iterable expression in the leftmost :keyword:`!for` clause is evaluated
|
||||
directly in the enclosing scope and then passed as an argument to the implictly
|
||||
nested scope. Subsequent :keyword:`for` clauses and any filter condition in the
|
||||
leftmost :keyword:`for` clause cannot be evaluated in the enclosing scope as
|
||||
nested scope. Subsequent :keyword:`!for` clauses and any filter condition in the
|
||||
leftmost :keyword:`!for` clause cannot be evaluated in the enclosing scope as
|
||||
they may depend on the values obtained from the leftmost iterable. For example:
|
||||
``[x*y for x in range(10) for y in range(x, x+10)]``.
|
||||
|
||||
|
@ -209,14 +209,14 @@ nested scope.
|
|||
.. index::
|
||||
single: await; in comprehensions
|
||||
|
||||
Since Python 3.6, in an :keyword:`async def` function, an :keyword:`async for`
|
||||
Since Python 3.6, in an :keyword:`async def` function, an :keyword:`!async for`
|
||||
clause may be used to iterate over a :term:`asynchronous iterator`.
|
||||
A comprehension in an :keyword:`async def` function may consist of either a
|
||||
:keyword:`for` or :keyword:`async for` clause following the leading
|
||||
expression, may contain additional :keyword:`for` or :keyword:`async for`
|
||||
A comprehension in an :keyword:`!async def` function may consist of either a
|
||||
:keyword:`!for` or :keyword:`!async for` clause following the leading
|
||||
expression, may contain additional :keyword:`!for` or :keyword:`!async for`
|
||||
clauses, and may also use :keyword:`await` expressions.
|
||||
If a comprehension contains either :keyword:`async for` clauses
|
||||
or :keyword:`await` expressions it is called an
|
||||
If a comprehension contains either :keyword:`!async for` clauses
|
||||
or :keyword:`!await` expressions it is called an
|
||||
:dfn:`asynchronous comprehension`. An asynchronous comprehension may
|
||||
suspend the execution of the coroutine function in which it appears.
|
||||
See also :pep:`530`.
|
||||
|
@ -360,11 +360,11 @@ brackets or curly braces.
|
|||
Variables used in the generator expression are evaluated lazily when the
|
||||
:meth:`~generator.__next__` method is called for the generator object (in the same
|
||||
fashion as normal generators). However, the iterable expression in the
|
||||
leftmost :keyword:`for` clause is immediately evaluated, so that an error
|
||||
leftmost :keyword:`!for` clause is immediately evaluated, so that an error
|
||||
produced by it will be emitted at the point where the generator expression
|
||||
is defined, rather than at the point where the first value is retrieved.
|
||||
Subsequent :keyword:`for` clauses and any filter condition in the leftmost
|
||||
:keyword:`for` clause cannot be evaluated in the enclosing scope as they may
|
||||
Subsequent :keyword:`!for` clauses and any filter condition in the leftmost
|
||||
:keyword:`!for` clause cannot be evaluated in the enclosing scope as they may
|
||||
depend on the values obtained from the leftmost iterable. For example:
|
||||
``(x*y for x in range(10) for y in range(x, x+10))``.
|
||||
|
||||
|
@ -375,7 +375,7 @@ To avoid interfering with the expected operation of the generator expression
|
|||
itself, ``yield`` and ``yield from`` expressions are prohibited in the
|
||||
implicitly defined generator.
|
||||
|
||||
If a generator expression contains either :keyword:`async for`
|
||||
If a generator expression contains either :keyword:`!async for`
|
||||
clauses or :keyword:`await` expressions it is called an
|
||||
:dfn:`asynchronous generator expression`. An asynchronous generator
|
||||
expression returns a new asynchronous generator object,
|
||||
|
@ -637,12 +637,12 @@ that method.
|
|||
In an asynchronous generator function, yield expressions are allowed anywhere
|
||||
in a :keyword:`try` construct. However, if an asynchronous generator is not
|
||||
resumed before it is finalized (by reaching a zero reference count or by
|
||||
being garbage collected), then a yield expression within a :keyword:`try`
|
||||
being garbage collected), then a yield expression within a :keyword:`!try`
|
||||
construct could result in a failure to execute pending :keyword:`finally`
|
||||
clauses. In this case, it is the responsibility of the event loop or
|
||||
scheduler running the asynchronous generator to call the asynchronous
|
||||
generator-iterator's :meth:`~agen.aclose` method and run the resulting
|
||||
coroutine object, thus allowing any pending :keyword:`finally` clauses
|
||||
coroutine object, thus allowing any pending :keyword:`!finally` clauses
|
||||
to execute.
|
||||
|
||||
To take care of finalization, an event loop should define
|
||||
|
@ -1548,7 +1548,7 @@ Membership test operations
|
|||
The operators :keyword:`in` and :keyword:`not in` test for membership. ``x in
|
||||
s`` evaluates to ``True`` if *x* is a member of *s*, and ``False`` otherwise.
|
||||
``x not in s`` returns the negation of ``x in s``. All built-in sequences and
|
||||
set types support this as well as dictionary, for which :keyword:`in` tests
|
||||
set types support this as well as dictionary, for which :keyword:`!in` tests
|
||||
whether the dictionary has a given key. For container types such as list, tuple,
|
||||
set, frozenset, dict, or collections.deque, the expression ``x in y`` is equivalent
|
||||
to ``any(x is e or x == e for e in y)``.
|
||||
|
@ -1648,6 +1648,8 @@ returns a boolean value regardless of the type of its argument
|
|||
(for example, ``not 'foo'`` produces ``False`` rather than ``''``.)
|
||||
|
||||
|
||||
.. _if_expr:
|
||||
|
||||
Conditional expressions
|
||||
=======================
|
||||
|
||||
|
@ -1790,7 +1792,7 @@ precedence and have a left-to-right chaining feature as described in the
|
|||
+===============================================+=====================================+
|
||||
| :keyword:`lambda` | Lambda expression |
|
||||
+-----------------------------------------------+-------------------------------------+
|
||||
| :keyword:`if` -- :keyword:`else` | Conditional expression |
|
||||
| :keyword:`if <if_expr>` -- :keyword:`!else` | Conditional expression |
|
||||
+-----------------------------------------------+-------------------------------------+
|
||||
| :keyword:`or` | Boolean OR |
|
||||
+-----------------------------------------------+-------------------------------------+
|
||||
|
|
|
@ -15,11 +15,11 @@ way. Functions such as :func:`importlib.import_module` and built-in
|
|||
|
||||
The :keyword:`import` statement combines two operations; it searches for the
|
||||
named module, then it binds the results of that search to a name in the local
|
||||
scope. The search operation of the :keyword:`import` statement is defined as
|
||||
scope. The search operation of the :keyword:`!import` statement is defined as
|
||||
a call to the :func:`__import__` function, with the appropriate arguments.
|
||||
The return value of :func:`__import__` is used to perform the name
|
||||
binding operation of the :keyword:`import` statement. See the
|
||||
:keyword:`import` statement for the exact details of that name binding
|
||||
binding operation of the :keyword:`!import` statement. See the
|
||||
:keyword:`!import` statement for the exact details of that name binding
|
||||
operation.
|
||||
|
||||
A direct call to :func:`__import__` performs only the module search and, if
|
||||
|
|
|
@ -369,11 +369,11 @@ target, then the interpreter evaluates the target except for the last
|
|||
|
||||
.. _assert:
|
||||
|
||||
The :keyword:`assert` statement
|
||||
===============================
|
||||
The :keyword:`!assert` statement
|
||||
================================
|
||||
|
||||
.. index::
|
||||
statement: assert
|
||||
! statement: assert
|
||||
pair: debugging; assertions
|
||||
single: , (comma); expression list
|
||||
|
||||
|
@ -412,8 +412,8 @@ is determined when the interpreter starts.
|
|||
|
||||
.. _pass:
|
||||
|
||||
The :keyword:`pass` statement
|
||||
=============================
|
||||
The :keyword:`!pass` statement
|
||||
==============================
|
||||
|
||||
.. index::
|
||||
statement: pass
|
||||
|
@ -434,11 +434,11 @@ code needs to be executed, for example::
|
|||
|
||||
.. _del:
|
||||
|
||||
The :keyword:`del` statement
|
||||
============================
|
||||
The :keyword:`!del` statement
|
||||
=============================
|
||||
|
||||
.. index::
|
||||
statement: del
|
||||
! statement: del
|
||||
pair: deletion; target
|
||||
triple: deletion; target; list
|
||||
|
||||
|
@ -473,11 +473,11 @@ the sliced object).
|
|||
|
||||
.. _return:
|
||||
|
||||
The :keyword:`return` statement
|
||||
===============================
|
||||
The :keyword:`!return` statement
|
||||
================================
|
||||
|
||||
.. index::
|
||||
statement: return
|
||||
! statement: return
|
||||
pair: function; definition
|
||||
pair: class; definition
|
||||
|
||||
|
@ -495,7 +495,7 @@ If an expression list is present, it is evaluated, else ``None`` is substituted.
|
|||
.. index:: keyword: finally
|
||||
|
||||
When :keyword:`return` passes control out of a :keyword:`try` statement with a
|
||||
:keyword:`finally` clause, that :keyword:`finally` clause is executed before
|
||||
:keyword:`finally` clause, that :keyword:`!finally` clause is executed before
|
||||
really leaving the function.
|
||||
|
||||
In a generator function, the :keyword:`return` statement indicates that the
|
||||
|
@ -505,13 +505,13 @@ becomes the :attr:`StopIteration.value` attribute.
|
|||
|
||||
In an asynchronous generator function, an empty :keyword:`return` statement
|
||||
indicates that the asynchronous generator is done and will cause
|
||||
:exc:`StopAsyncIteration` to be raised. A non-empty :keyword:`return`
|
||||
:exc:`StopAsyncIteration` to be raised. A non-empty :keyword:`!return`
|
||||
statement is a syntax error in an asynchronous generator function.
|
||||
|
||||
.. _yield:
|
||||
|
||||
The :keyword:`yield` statement
|
||||
==============================
|
||||
The :keyword:`!yield` statement
|
||||
===============================
|
||||
|
||||
.. index::
|
||||
statement: yield
|
||||
|
@ -546,11 +546,11 @@ For full details of :keyword:`yield` semantics, refer to the
|
|||
|
||||
.. _raise:
|
||||
|
||||
The :keyword:`raise` statement
|
||||
==============================
|
||||
The :keyword:`!raise` statement
|
||||
===============================
|
||||
|
||||
.. index::
|
||||
statement: raise
|
||||
! statement: raise
|
||||
single: exception
|
||||
pair: raising; exception
|
||||
single: __traceback__ (exception attribute)
|
||||
|
@ -649,11 +649,11 @@ and information about handling exceptions is in section :ref:`try`.
|
|||
|
||||
.. _break:
|
||||
|
||||
The :keyword:`break` statement
|
||||
==============================
|
||||
The :keyword:`!break` statement
|
||||
===============================
|
||||
|
||||
.. index::
|
||||
statement: break
|
||||
! statement: break
|
||||
statement: for
|
||||
statement: while
|
||||
pair: loop; statement
|
||||
|
@ -668,7 +668,7 @@ that loop.
|
|||
.. index:: keyword: else
|
||||
pair: loop control; target
|
||||
|
||||
It terminates the nearest enclosing loop, skipping the optional :keyword:`else`
|
||||
It terminates the nearest enclosing loop, skipping the optional :keyword:`!else`
|
||||
clause if the loop has one.
|
||||
|
||||
If a :keyword:`for` loop is terminated by :keyword:`break`, the loop control
|
||||
|
@ -677,17 +677,17 @@ target keeps its current value.
|
|||
.. index:: keyword: finally
|
||||
|
||||
When :keyword:`break` passes control out of a :keyword:`try` statement with a
|
||||
:keyword:`finally` clause, that :keyword:`finally` clause is executed before
|
||||
:keyword:`finally` clause, that :keyword:`!finally` clause is executed before
|
||||
really leaving the loop.
|
||||
|
||||
|
||||
.. _continue:
|
||||
|
||||
The :keyword:`continue` statement
|
||||
=================================
|
||||
The :keyword:`!continue` statement
|
||||
==================================
|
||||
|
||||
.. index::
|
||||
statement: continue
|
||||
! statement: continue
|
||||
statement: for
|
||||
statement: while
|
||||
pair: loop; statement
|
||||
|
@ -701,18 +701,18 @@ The :keyword:`continue` statement
|
|||
that loop. It continues with the next cycle of the nearest enclosing loop.
|
||||
|
||||
When :keyword:`continue` passes control out of a :keyword:`try` statement with a
|
||||
:keyword:`finally` clause, that :keyword:`finally` clause is executed before
|
||||
:keyword:`finally` clause, that :keyword:`!finally` clause is executed before
|
||||
really starting the next loop cycle.
|
||||
|
||||
|
||||
.. _import:
|
||||
.. _from:
|
||||
|
||||
The :keyword:`import` statement
|
||||
===============================
|
||||
The :keyword:`!import` statement
|
||||
================================
|
||||
|
||||
.. index::
|
||||
statement: import
|
||||
! statement: import
|
||||
single: module; importing
|
||||
pair: name; binding
|
||||
keyword: from
|
||||
|
@ -755,8 +755,8 @@ available in the local namespace in one of three ways:
|
|||
|
||||
.. index:: single: as; import statement
|
||||
|
||||
* If the module name is followed by :keyword:`as`, then the name
|
||||
following :keyword:`as` is bound directly to the imported module.
|
||||
* If the module name is followed by :keyword:`!as`, then the name
|
||||
following :keyword:`!as` is bound directly to the imported module.
|
||||
* If no other name is specified, and the module being imported is a top
|
||||
level module, the module's name is bound in the local namespace as a
|
||||
reference to the imported module
|
||||
|
@ -781,7 +781,7 @@ The :keyword:`from` form uses a slightly more complex process:
|
|||
check the imported module again for that attribute
|
||||
#. if the attribute is not found, :exc:`ImportError` is raised.
|
||||
#. otherwise, a reference to that value is stored in the local namespace,
|
||||
using the name in the :keyword:`as` clause if it is present,
|
||||
using the name in the :keyword:`!as` clause if it is present,
|
||||
otherwise using the attribute name
|
||||
|
||||
Examples::
|
||||
|
@ -922,11 +922,11 @@ after the script is executed.
|
|||
|
||||
.. _global:
|
||||
|
||||
The :keyword:`global` statement
|
||||
===============================
|
||||
The :keyword:`!global` statement
|
||||
================================
|
||||
|
||||
.. index::
|
||||
statement: global
|
||||
! statement: global
|
||||
triple: global; name; binding
|
||||
single: , (comma); identifier list
|
||||
|
||||
|
@ -936,11 +936,11 @@ The :keyword:`global` statement
|
|||
The :keyword:`global` statement is a declaration which holds for the entire
|
||||
current code block. It means that the listed identifiers are to be interpreted
|
||||
as globals. It would be impossible to assign to a global variable without
|
||||
:keyword:`global`, although free variables may refer to globals without being
|
||||
:keyword:`!global`, although free variables may refer to globals without being
|
||||
declared global.
|
||||
|
||||
Names listed in a :keyword:`global` statement must not be used in the same code
|
||||
block textually preceding that :keyword:`global` statement.
|
||||
block textually preceding that :keyword:`!global` statement.
|
||||
|
||||
Names listed in a :keyword:`global` statement must not be defined as formal
|
||||
parameters or in a :keyword:`for` loop control target, :keyword:`class`
|
||||
|
@ -959,18 +959,18 @@ annotation.
|
|||
builtin: compile
|
||||
|
||||
**Programmer's note:** :keyword:`global` is a directive to the parser. It
|
||||
applies only to code parsed at the same time as the :keyword:`global` statement.
|
||||
In particular, a :keyword:`global` statement contained in a string or code
|
||||
applies only to code parsed at the same time as the :keyword:`!global` statement.
|
||||
In particular, a :keyword:`!global` statement contained in a string or code
|
||||
object supplied to the built-in :func:`exec` function does not affect the code
|
||||
block *containing* the function call, and code contained in such a string is
|
||||
unaffected by :keyword:`global` statements in the code containing the function
|
||||
unaffected by :keyword:`!global` statements in the code containing the function
|
||||
call. The same applies to the :func:`eval` and :func:`compile` functions.
|
||||
|
||||
|
||||
.. _nonlocal:
|
||||
|
||||
The :keyword:`nonlocal` statement
|
||||
=================================
|
||||
The :keyword:`!nonlocal` statement
|
||||
==================================
|
||||
|
||||
.. index:: statement: nonlocal
|
||||
single: , (comma); identifier list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue