Simplify index entries; fix #1712.

This commit is contained in:
Georg Brandl 2008-01-05 19:29:45 +00:00
parent 9749e15e2f
commit 6265833d91
3 changed files with 70 additions and 97 deletions

View File

@ -76,7 +76,10 @@ on a separate line for clarity.
The :keyword:`if` statement The :keyword:`if` statement
=========================== ===========================
.. index:: statement: if .. index::
statement: if
keyword: elif
keyword: else
The :keyword:`if` statement is used for conditional execution: The :keyword:`if` statement is used for conditional execution:
@ -85,10 +88,6 @@ The :keyword:`if` statement is used for conditional execution:
: ( "elif" `expression` ":" `suite` )* : ( "elif" `expression` ":" `suite` )*
: ["else" ":" `suite`] : ["else" ":" `suite`]
.. index::
keyword: elif
keyword: else
It selects exactly one of the suites by evaluating the expressions one by one It selects exactly one of the suites by evaluating the expressions one by one
until one is found to be true (see section :ref:`booleans` for the definition of until one is found to be true (see section :ref:`booleans` for the definition of
true and false); then that suite is executed (and no other part of the true and false); then that suite is executed (and no other part of the
@ -104,6 +103,7 @@ The :keyword:`while` statement
.. index:: .. index::
statement: while statement: while
pair: loop; statement pair: loop; statement
keyword: else
The :keyword:`while` statement is used for repeated execution as long as an The :keyword:`while` statement is used for repeated execution as long as an
expression is true: expression is true:
@ -112,8 +112,6 @@ expression is true:
while_stmt: "while" `expression` ":" `suite` while_stmt: "while" `expression` ":" `suite`
: ["else" ":" `suite`] : ["else" ":" `suite`]
.. index:: keyword: else
This repeatedly tests the expression and, if it is true, executes the first 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; 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
@ -137,8 +135,10 @@ The :keyword:`for` statement
.. index:: .. index::
statement: for statement: for
pair: loop; statement pair: loop; statement
keyword: in
.. index:: object: sequence keyword: else
pair: target; list
object: sequence
The :keyword:`for` statement is used to iterate over the elements of a sequence The :keyword:`for` statement is used to iterate over the elements of a sequence
(such as a string, tuple or list) or other iterable object: (such as a string, tuple or list) or other iterable object:
@ -147,11 +147,6 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence
for_stmt: "for" `target_list` "in" `expression_list` ":" `suite` for_stmt: "for" `target_list` "in" `expression_list` ":" `suite`
: ["else" ":" `suite`] : ["else" ":" `suite`]
.. index::
keyword: in
keyword: else
pair: target; list
The expression list is evaluated once; it should yield an iterable object. An The expression list is evaluated once; it should yield an iterable object. An
iterator is created for the result of the ``expression_list``. The suite is iterator is created for the result of the ``expression_list``. The suite is
then executed once for each item provided by the iterator, in the order of then executed once for each item provided by the iterator, in the order of
@ -214,7 +209,10 @@ effect of Pascal's ``for i := a to b do``; e.g., ``range(3)`` returns the list
The :keyword:`try` statement The :keyword:`try` statement
============================ ============================
.. index:: statement: try .. index::
statement: try
keyword: except
keyword: finally
The :keyword:`try` statement specifies exception handlers and/or cleanup code The :keyword:`try` statement specifies exception handlers and/or cleanup code
for a group of statements: for a group of statements:
@ -233,8 +231,6 @@ for a group of statements:
:keyword:`finally` did not work. :keyword:`try`...\ :keyword:`except` had to be :keyword:`finally` did not work. :keyword:`try`...\ :keyword:`except` had to be
nested in :keyword:`try`...\ :keyword:`finally`. nested in :keyword:`try`...\ :keyword:`finally`.
.. index:: keyword: except
The :keyword:`except` clause(s) specify one or more exception handlers. When no 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. 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
@ -376,12 +372,8 @@ The execution of the :keyword:`with` statement proceeds as follows:
.. note:: .. note::
In Python 2.5, the :keyword:`with` statement is only allowed when the In Python 2.5, the :keyword:`with` statement is only allowed when the
``with_statement`` feature has been enabled. It will always be enabled in ``with_statement`` feature has been enabled. It is always enabled in
Python 2.6. This ``__future__`` import statement can be used to enable the Python 2.6.
feature::
from __future__ import with_statement
.. seealso:: .. seealso::
@ -397,10 +389,10 @@ Function definitions
==================== ====================
.. index:: .. index::
pair: function; definition
statement: def statement: def
pair: function; definition
.. index:: pair: function; name
pair: name; binding
object: user-defined function object: user-defined function
object: function object: function
@ -421,10 +413,6 @@ A function definition defines a user-defined function object (see section
parameter: `identifier` | "(" `sublist` ")" parameter: `identifier` | "(" `sublist` ")"
funcname: `identifier` funcname: `identifier`
.. index::
pair: function; name
pair: name; binding
A function definition is an executable statement. Its execution binds the A function definition is an executable statement. Its execution binds the
function name in the current local namespace to a function object (a wrapper function name in the current local namespace to a function object (a wrapper
around the executable code for the function). This function object contains a around the executable code for the function). This function object contains a
@ -505,10 +493,13 @@ Class definitions
================= =================
.. index:: .. index::
pair: class; definition object: class
statement: class statement: class
pair: class; definition
.. index:: object: class pair: class; name
pair: name; binding
pair: execution; frame
single: inheritance
A class definition defines a class object (see section :ref:`types`): A class definition defines a class object (see section :ref:`types`):
@ -517,12 +508,6 @@ A class definition defines a class object (see section :ref:`types`):
inheritance: "(" [`expression_list`] ")" inheritance: "(" [`expression_list`] ")"
classname: `identifier` classname: `identifier`
.. index::
single: inheritance
pair: class; name
pair: name; binding
pair: execution; frame
A class definition is an executable statement. It first evaluates the A class definition is an executable statement. It first evaluates the
inheritance list, if present. Each item in the inheritance list should evaluate inheritance list, if present. Each item in the inheritance list should evaluate
to a class object or class type which allows subclassing. The class's suite is to a class object or class type which allows subclassing. The class's suite is
@ -535,13 +520,13 @@ the saved local namespace for the attribute dictionary. The class name is bound
to this class object in the original local namespace. to this class object in the original local namespace.
**Programmer's note:** Variables defined in the class definition are class **Programmer's note:** Variables defined in the class definition are class
variables; they are shared by all instances. To define instance variables, they variables; they are shared by all instances. To create instance variables, they
must be given a value in the :meth:`__init__` method or in another method. Both can be set in a method with ``self.name = value``. Both class and instance
class and instance variables are accessible through the notation variables are accessible through the notation "``self.name``", and an instance
"``self.name``", and an instance variable hides a class variable with the same variable hides a class variable with the same name when accessed in this way.
name when accessed in this way. Class variables with immutable values can be Class variables can be used as defaults for instance variables, but using
used as defaults for instance variables. For :term:`new-style class`\es, mutable values there can lead to unexpected results. For :term:`new-style
descriptors can be used to create instance variables with different class`\es, descriptors can be used to create instance variables with different
implementation details. implementation details.
.. rubric:: Footnotes .. rubric:: Footnotes
@ -552,4 +537,3 @@ implementation details.
.. [#] Currently, control "flows off the end" except in the case of an exception or the .. [#] Currently, control "flows off the end" except in the case of an exception or the
execution of a :keyword:`return`, :keyword:`continue`, or :keyword:`break` execution of a :keyword:`return`, :keyword:`continue`, or :keyword:`break`
statement. statement.

View File

@ -1097,16 +1097,15 @@ implemented before for compatibility concerns, like the method resolution order
in case of multiple inheritance. in case of multiple inheritance.
This manual is not up-to-date with respect to new-style classes. For now, This manual is not up-to-date with respect to new-style classes. For now,
please see http://www.python.org/doc/newstyle.html for more information. please see http://www.python.org/doc/newstyle/ for more information.
.. index:: .. index::
single: class single: class; new-style
single: class single: class; classic
single: class single: class; old-style
The plan is to eventually drop old-style classes, leaving only the semantics of The plan is to eventually drop old-style classes, leaving only the semantics of
new-style classes. This change will probably only be feasible in Python 3.0. new-style classes. This change will probably only be feasible in Python 3.0.
new-style classic old-style
.. _specialnames: .. _specialnames:
@ -2242,7 +2241,7 @@ For more information on context managers, see :ref:`typecontextmanager`.
extensive revision, it must now be taken as authoritative only regarding extensive revision, it must now be taken as authoritative only regarding
"classic classes", that are still the default, for compatibility purposes, in "classic classes", that are still the default, for compatibility purposes, in
Python 2.2 and 2.3. For more information, see Python 2.2 and 2.3. For more information, see
http://www.python.org/doc/newstyle.html. http://www.python.org/doc/newstyle/.
.. [#] This, and other statements, are only roughly true for instances of new-style .. [#] This, and other statements, are only roughly true for instances of new-style
classes. classes.

View File

@ -34,7 +34,9 @@ simple statements is:
Expression statements Expression statements
===================== =====================
.. index:: pair: expression; statement .. index::
pair: expression; statement
pair: expression; list
Expression statements are used (mostly interactively) to compute and write a Expression statements are used (mostly interactively) to compute and write a
value, or (usually) to call a procedure (a function that returns no meaningful value, or (usually) to call a procedure (a function that returns no meaningful
@ -45,8 +47,6 @@ expression statement is:
.. productionlist:: .. productionlist::
expression_stmt: `expression_list` expression_stmt: `expression_list`
.. index:: pair: expression; list
An expression statement evaluates the expression list (which may be a single An expression statement evaluates the expression list (which may be a single
expression). expression).
@ -311,13 +311,13 @@ is determined when the interpreter starts.
The :keyword:`pass` statement The :keyword:`pass` statement
============================= =============================
.. index:: statement: pass .. index::
statement: pass
pair: null; operation
.. productionlist:: .. productionlist::
pass_stmt: "pass" pass_stmt: "pass"
.. index:: pair: null; operation
:keyword:`pass` is a null operation --- when it is executed, nothing happens. :keyword:`pass` is a null operation --- when it is executed, nothing happens.
It is useful as a placeholder when a statement is required syntactically, but no It is useful as a placeholder when a statement is required syntactically, but no
code needs to be executed, for example:: code needs to be executed, for example::
@ -332,15 +332,14 @@ code needs to be executed, for example::
The :keyword:`del` statement The :keyword:`del` statement
============================ ============================
.. index:: statement: del .. index::
statement: del
pair: deletion; target
triple: deletion; target; list
.. productionlist:: .. productionlist::
del_stmt: "del" `target_list` del_stmt: "del" `target_list`
.. index::
pair: deletion; target
triple: deletion; target; list
Deletion is recursively defined very similar to the way assignment is defined. Deletion is recursively defined very similar to the way assignment is defined.
Rather that spelling it out in full details, here are some hints. Rather that spelling it out in full details, here are some hints.
@ -399,8 +398,6 @@ functional to write an empty string to standard output for this reason.)
.. index:: .. index::
single: output single: output
pair: writing; values pair: writing; values
.. index::
pair: trailing; comma pair: trailing; comma
pair: newline; suppression pair: newline; suppression
@ -434,15 +431,14 @@ then ``sys.stdout`` is used as the file for output.
The :keyword:`return` statement The :keyword:`return` statement
=============================== ===============================
.. index:: statement: return .. index::
statement: return
pair: function; definition
pair: class; definition
.. productionlist:: .. productionlist::
return_stmt: "return" [`expression_list`] return_stmt: "return" [`expression_list`]
.. index::
pair: function; definition
pair: class; definition
:keyword:`return` may only occur syntactically nested in a function definition, :keyword:`return` may only occur syntactically nested in a function definition,
not within a nested class definition. not within a nested class definition.
@ -468,17 +464,16 @@ raised.
The :keyword:`yield` statement The :keyword:`yield` statement
============================== ==============================
.. index:: statement: yield
.. productionlist::
yield_stmt: `yield_expression`
.. index:: .. index::
statement: yield
single: generator; function single: generator; function
single: generator; iterator single: generator; iterator
single: function; generator single: function; generator
exception: StopIteration exception: StopIteration
.. productionlist::
yield_stmt: `yield_expression`
The :keyword:`yield` statement is only used when defining a generator function, The :keyword:`yield` statement is only used when defining a generator function,
and is only used in the body of the generator function. Using a :keyword:`yield` and is only used in the body of the generator function. Using a :keyword:`yield`
statement in a function definition is sufficient to cause that definition to statement in a function definition is sufficient to cause that definition to
@ -528,15 +523,14 @@ clauses to execute.
The :keyword:`raise` statement The :keyword:`raise` statement
============================== ==============================
.. index:: statement: raise .. index::
statement: raise
single: exception
pair: raising; exception
.. productionlist:: .. productionlist::
raise_stmt: "raise" [`expression` ["," `expression` ["," `expression`]]] raise_stmt: "raise" [`expression` ["," `expression` ["," `expression`]]]
.. index::
single: exception
pair: raising; exception
If no expressions are present, :keyword:`raise` re-raises the last exception If no expressions are present, :keyword:`raise` re-raises the last exception
that was active in the current scope. If no exception is active in the current that was active in the current scope. If no exception is active in the current
scope, a :exc:`TypeError` exception is raised indicating that this is an error scope, a :exc:`TypeError` exception is raised indicating that this is an error
@ -578,16 +572,15 @@ and information about handling exceptions is in section :ref:`try`.
The :keyword:`break` statement The :keyword:`break` statement
============================== ==============================
.. index:: statement: break
.. productionlist::
break_stmt: "break"
.. index:: .. index::
statement: break
statement: for statement: for
statement: while statement: while
pair: loop; statement pair: loop; statement
.. productionlist::
break_stmt: "break"
:keyword:`break` may only occur syntactically nested in a :keyword:`for` or :keyword:`break` may only occur syntactically nested in a :keyword:`for` or
:keyword:`while` loop, but not nested in a function or class definition within :keyword:`while` loop, but not nested in a function or class definition within
that loop. that loop.
@ -614,17 +607,16 @@ really leaving the loop.
The :keyword:`continue` statement The :keyword:`continue` statement
================================= =================================
.. index:: statement: continue
.. productionlist::
continue_stmt: "continue"
.. index:: .. index::
statement: continue
statement: for statement: for
statement: while statement: while
pair: loop; statement pair: loop; statement
keyword: finally keyword: finally
.. productionlist::
continue_stmt: "continue"
:keyword:`continue` may only occur syntactically nested in a :keyword:`for` or :keyword:`continue` may only occur syntactically nested in a :keyword:`for` or
:keyword:`while` loop, but not nested in a function or class definition or :keyword:`while` loop, but not nested in a function or class definition or
:keyword:`finally` statement within that loop. [#]_ It continues with the next :keyword:`finally` statement within that loop. [#]_ It continues with the next
@ -739,8 +731,6 @@ raise a :exc:`SyntaxError`.
.. index:: .. index::
keyword: from keyword: from
statement: from statement: from
.. index::
triple: hierarchical; module; names triple: hierarchical; module; names
single: packages single: packages
single: __init__.py single: __init__.py
@ -840,13 +830,13 @@ after the script is executed.
The :keyword:`global` statement The :keyword:`global` statement
=============================== ===============================
.. index:: statement: global .. index::
statement: global
triple: global; name; binding
.. productionlist:: .. productionlist::
global_stmt: "global" `identifier` ("," `identifier`)* global_stmt: "global" `identifier` ("," `identifier`)*
.. index:: triple: global; name; binding
The :keyword:`global` statement is a declaration which holds for the entire 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 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 as globals. It would be impossible to assign to a global variable without
@ -908,7 +898,7 @@ variables. If two expressions are given, they are used for the global and local
variables, respectively. If provided, *locals* can be any mapping object. variables, respectively. If provided, *locals* can be any mapping object.
.. versionchanged:: 2.4 .. versionchanged:: 2.4
formerly *locals* was required to be a dictionary. Formerly, *locals* was required to be a dictionary.
.. index:: .. index::
single: __builtins__ single: __builtins__