bpo-35054: Add more index entries for symbols. (GH-10064)

This commit is contained in:
Serhiy Storchaka 2018-10-26 09:00:49 +03:00 committed by GitHub
parent 3ec9af75f6
commit ddb961d2ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 466 additions and 64 deletions

View file

@ -21,6 +21,7 @@ also syntactically compound statements.
.. index::
single: clause
single: suite
single: ;
A compound statement consists of one or more 'clauses.' A clause consists of a
header and a 'suite.' The clause headers of a particular compound statement are
@ -84,8 +85,7 @@ The :keyword:`if` statement
statement: if
keyword: elif
keyword: else
keyword: elif
keyword: else
single: :; compound statement
The :keyword:`if` statement is used for conditional execution:
@ -111,6 +111,7 @@ The :keyword:`while` statement
keyword: else
pair: loop; statement
keyword: else
single: :; compound statement
The :keyword:`while` statement is used for repeated execution as long as an
expression is true:
@ -149,6 +150,7 @@ The :keyword:`for` statement
keyword: else
pair: target; list
object: sequence
single: :; compound statement
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:
@ -229,7 +231,9 @@ The :keyword:`try` statement
statement: try
keyword: except
keyword: finally
.. index:: keyword: except
keyword: else
keyword: as
single: :; compound statement
The :keyword:`try` statement specifies exception handlers and/or cleanup code
for a group of statements:
@ -263,6 +267,8 @@ exception, the original search for a handler is canceled and a search starts for
the new exception in the surrounding code and on the call stack (it is treated
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
the except clause's suite is executed. All except clauses must have an
@ -375,8 +381,11 @@ The :keyword:`with` statement
=============================
.. index::
statement: with
single: as; with statement
statement: with
keyword: as
single: as; with statement
single: ,; with statement
single: :; compound statement
The :keyword:`with` statement is used to wrap the execution of a block with
methods defined by a context manager (see section :ref:`context-managers`).
@ -463,6 +472,10 @@ Function definitions
object: function
pair: function; name
pair: name; binding
single: (; function definition
single: ); function definition
single: ,; parameter list
single: :; compound statement
A function definition defines a user-defined function object (see section
:ref:`types`):
@ -492,7 +505,7 @@ The function definition does not execute the function body; this gets executed
only when the function is called. [#]_
.. index::
statement: @
single: @; function definition
A function definition may be wrapped by one or more :term:`decorator` expressions.
Decorator expressions are evaluated when the function is defined, in the scope
@ -515,6 +528,7 @@ except that the original function is not temporarily bound to the name ``func``.
.. index::
triple: default; parameter; value
single: argument; function definition
single: =; function definition
When one or more :term:`parameters <parameter>` have the form *parameter* ``=``
*expression*, the function is said to have "default parameter values." For a
@ -541,8 +555,8 @@ e.g.::
return penguin
.. index::
statement: *
statement: **
single: *; function definition
single: **; function definition
Function call semantics are described in more detail in section :ref:`calls`. A
function call always assigns values to all parameters mentioned in the parameter
@ -555,7 +569,10 @@ new empty mapping of the same type. Parameters after "``*``" or
"``*identifier``" are keyword-only parameters and may only be passed
used keyword arguments.
.. index:: pair: function; annotations
.. index::
pair: function; annotations
single: ->; function annotations
single: :; function annotations
Parameters may have annotations of the form "``: expression``" following the
parameter name. Any parameter may have an annotation even those of the form
@ -617,6 +634,10 @@ Class definitions
pair: execution; frame
single: inheritance
single: docstring
single: (; class definition
single: ); class definition
single: ,; expression list
single: :; compound statement
A class definition defines a class object (see section :ref:`types`):
@ -655,6 +676,9 @@ the definition syntax.
Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
.. index::
single: @; class definition
Classes can also be decorated: just like when decorating functions, ::
@f1(arg)

View file

@ -165,7 +165,9 @@ NotImplemented
Ellipsis
.. index:: object: Ellipsis
.. index::
object: Ellipsis
single: ...; ellipsis literal
This type has a single value. There is a single object with this value. This
object is accessed through the literal ``...`` or the built-in name
@ -1831,8 +1833,9 @@ Metaclasses
^^^^^^^^^^^
.. index::
single: metaclass
builtin: type
single: metaclass
builtin: type
single: =; class definition
By default, classes are constructed using :func:`type`. The class body is
executed in a new namespace and the class name is bound locally to the

View file

@ -52,7 +52,7 @@ Binding of names
:dfn:`Names` refer to objects. Names are introduced by name binding operations.
.. index:: statement: from
.. index:: single: from; import statement
The following constructs bind names: formal parameters to functions,
:keyword:`import` statements, class and function definitions (these bind the

View file

@ -128,7 +128,10 @@ value.
Parenthesized forms
-------------------
.. index:: single: parenthesized form
.. index::
single: parenthesized form
single: (; tuple display
single: ); tuple display
A parenthesized form is an optional expression list enclosed in parentheses:
@ -146,8 +149,9 @@ immutable, the rules for literals apply (i.e., two occurrences of the empty
tuple may or may not yield the same object).
.. index::
single: comma
single: comma; tuple display
pair: tuple; display
single: ,; tuple display
Note that tuples are not formed by the parentheses, but rather by use of the
comma operator. The exception is the empty tuple, for which parentheses *are*
@ -168,6 +172,11 @@ called "displays", each of them in two flavors:
* they are computed via a set of looping and filtering instructions, called a
:dfn:`comprehension`.
.. index::
single: for; in comprehensions
single: if; in comprehensions
single: async for; in comprehensions
Common syntax elements for comprehensions are:
.. productionlist::
@ -198,6 +207,9 @@ To ensure the comprehension always results in a container of the appropriate
type, ``yield`` and ``yield from`` expressions are prohibited in the implicitly
nested scope.
.. index::
single: await; in comprehensions
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
@ -227,6 +239,9 @@ List displays
pair: list; comprehensions
pair: empty; list
object: list
single: [; list expression
single: ]; list expression
single: ,; expression list
A list display is a possibly empty series of expressions enclosed in square
brackets:
@ -246,8 +261,12 @@ the list is constructed from the elements resulting from the comprehension.
Set displays
------------
.. index:: pair: set; display
object: set
.. index::
pair: set; display
object: set
single: {; set expression
single: }; set expression
single: ,; expression list
A set display is denoted by curly braces and distinguishable from dictionary
displays by the lack of colons separating keys and values:
@ -270,9 +289,14 @@ dictionary.
Dictionary displays
-------------------
.. index:: pair: dictionary; display
key, datum, key/datum pair
object: dictionary
.. index::
pair: dictionary; display
key, datum, key/datum pair
object: dictionary
single: {; dictionary expression
single: }; dictionary expression
single: :; in dictionary expressions
single: ,; in dictionary displays
A dictionary display is a possibly empty series of key/datum pairs enclosed in
curly braces:
@ -291,7 +315,9 @@ used as a key into the dictionary to store the corresponding datum. This means
that you can specify the same key multiple times in the key/datum list, and the
final dictionary's value for that key will be the last one given.
.. index:: unpacking; dictionary, **; in dictionary displays
.. index::
unpacking; dictionary
single: **; in dictionary displays
A double asterisk ``**`` denotes :dfn:`dictionary unpacking`.
Its operand must be a :term:`mapping`. Each mapping item is added
@ -321,8 +347,11 @@ prevails.
Generator expressions
---------------------
.. index:: pair: generator; expression
object: generator
.. index::
pair: generator; expression
object: generator
single: (; generator expression
single: ); generator expression
A generator expression is a compact generator notation in parentheses:
@ -376,6 +405,7 @@ Yield expressions
.. index::
keyword: yield
keyword: from
pair: yield; expression
pair: generator; function
@ -439,6 +469,9 @@ finalized (by reaching a zero reference count or by being garbage collected),
the generator-iterator's :meth:`~generator.close` method will be called,
allowing any pending :keyword:`finally` clauses to execute.
.. index::
single: from; yield from expression
When ``yield from <expr>`` is used, it treats the supplied expression as
a subiterator. All values produced by that subiterator are passed directly
to the caller of the current generator's methods. Any values passed in with
@ -718,7 +751,9 @@ syntax is:
Attribute references
--------------------
.. index:: pair: attribute; reference
.. index::
pair: attribute; reference
single: .; attribute reference
An attribute reference is a primary followed by a period and a name:
@ -744,7 +779,10 @@ same attribute reference may yield different objects.
Subscriptions
-------------
.. index:: single: subscription
.. index::
single: subscription
single: [; subscription
single: ]; subscription
.. index::
object: sequence
@ -801,6 +839,8 @@ Slicings
.. index::
single: slicing
single: slice
single: :; slicing
single: ,; slicing
.. index::
object: sequence
@ -850,6 +890,10 @@ substituting ``None`` for missing expressions.
object: callable
single: call
single: argument; call semantics
single: (; call
single: ); call
single: ,; argument list
single: =; in function calls
.. _calls:
@ -1032,6 +1076,7 @@ a class instance:
if that method was called.
.. index:: keyword: await
.. _await:
Await expression
@ -1051,6 +1096,10 @@ Can only be used inside a :term:`coroutine function`.
The power operator
==================
.. index::
pair: power; operation
operator: **
The power operator binds more tightly than unary operators on its left; it binds
less tightly than unary operators on its right. The syntax is:
@ -1093,15 +1142,21 @@ All unary arithmetic and bitwise operations have the same priority:
.. index::
single: negation
single: minus
single: operator; -
single: -; unary operator
The unary ``-`` (minus) operator yields the negation of its numeric argument.
.. index:: single: plus
.. index::
single: plus
single: operator; +
single: +; unary operator
The unary ``+`` (plus) operator yields its numeric argument unchanged.
.. index:: single: inversion
.. index::
single: inversion
operator: ~
The unary ``~`` (invert) operator yields the bitwise inversion of its integer
argument. The bitwise inversion of ``x`` is defined as ``-(x+1)``. It only
@ -1131,7 +1186,9 @@ operators and one for additive operators:
: `m_expr` "%" `u_expr`
a_expr: `m_expr` | `a_expr` "+" `m_expr` | `a_expr` "-" `m_expr`
.. index:: single: multiplication
.. index::
single: multiplication
operator: *
The ``*`` (multiplication) operator yields the product of its arguments. The
arguments must either both be numbers, or one argument must be an integer and
@ -1151,6 +1208,8 @@ builtin Python types implement this operator.
.. index::
exception: ZeroDivisionError
single: division
operator: /
operator: //
The ``/`` (division) and ``//`` (floor division) operators yield the quotient of
their arguments. The numeric arguments are first converted to a common type.
@ -1159,7 +1218,9 @@ integer; the result is that of mathematical division with the 'floor' function
applied to the result. Division by zero raises the :exc:`ZeroDivisionError`
exception.
.. index:: single: modulo
.. index::
single: modulo
operator: %
The ``%`` (modulo) operator yields the remainder from the division of the first
argument by the second. The numeric arguments are first converted to a common
@ -1184,14 +1245,20 @@ The floor division operator, the modulo operator, and the :func:`divmod`
function are not defined for complex numbers. Instead, convert to a floating
point number using the :func:`abs` function if appropriate.
.. index:: single: addition
.. index::
single: addition
single: operator; +
single: +; binary operator
The ``+`` (addition) operator yields the sum of its arguments. The arguments
must either both be numbers or both be sequences of the same type. In the
former case, the numbers are converted to a common type and then added together.
In the latter case, the sequences are concatenated.
.. index:: single: subtraction
.. index::
single: subtraction
single: operator; -
single: -; binary operator
The ``-`` (subtraction) operator yields the difference of its arguments. The
numeric arguments are first converted to a common type.
@ -1202,7 +1269,10 @@ numeric arguments are first converted to a common type.
Shifting operations
===================
.. index:: pair: shifting; operation
.. index::
pair: shifting; operation
operator: <<
operator: >>
The shifting operations have lower priority than the arithmetic operations:
@ -1232,7 +1302,9 @@ Each of the three bitwise operations has a different priority level:
xor_expr: `and_expr` | `xor_expr` "^" `and_expr`
or_expr: `xor_expr` | `or_expr` "|" `xor_expr`
.. index:: pair: bitwise; and
.. index::
pair: bitwise; and
operator: &
The ``&`` operator yields the bitwise AND of its arguments, which must be
integers.
@ -1240,6 +1312,7 @@ integers.
.. index::
pair: bitwise; xor
pair: exclusive; or
operator: ^
The ``^`` operator yields the bitwise XOR (exclusive OR) of its arguments, which
must be integers.
@ -1247,6 +1320,7 @@ must be integers.
.. index::
pair: bitwise; or
pair: inclusive; or
operator: |
The ``|`` operator yields the bitwise (inclusive) OR of its arguments, which
must be integers.
@ -1257,9 +1331,15 @@ must be integers.
Comparisons
===========
.. index:: single: comparison
.. index:: pair: C; language
.. index::
single: comparison
pair: C; language
operator: <
operator: >
operator: <=
operator: >=
operator: ==
operator: !=
Unlike C, all comparison operations in Python have the same priority, which is
lower than that of any arithmetic, shifting or bitwise operation. Also unlike
@ -1577,6 +1657,8 @@ Conditional expressions
.. index::
pair: conditional; expression
pair: ternary; operator
single: if; conditional expression
single: else; conditional expression
.. productionlist::
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
@ -1603,10 +1685,11 @@ Lambdas
pair: lambda; expression
pair: lambda; form
pair: anonymous; function
single: :; lambda expression
.. productionlist::
lambda_expr: "lambda" [`parameter_list`]: `expression`
lambda_expr_nocond: "lambda" [`parameter_list`]: `expression_nocond`
lambda_expr: "lambda" [`parameter_list`] ":" `expression`
lambda_expr_nocond: "lambda" [`parameter_list`] ":" `expression_nocond`
Lambda expressions (sometimes called lambda forms) are used to create anonymous
functions. The expression ``lambda parameters: expression`` yields a function
@ -1627,7 +1710,10 @@ annotations.
Expression lists
================
.. index:: pair: expression; list
.. index::
pair: expression; list
single: comma; expression list
single: ,; expression list
.. productionlist::
expression_list: `expression` ("," `expression`)* [","]
@ -1689,7 +1775,8 @@ their suffixes::
Operator precedence
===================
.. index:: pair: operator; precedence
.. index::
pair: operator; precedence
The following table summarizes the operator precedence in Python, from lowest
precedence (least binding) to highest precedence (most binding). Operators in
@ -1737,7 +1824,7 @@ precedence and have a left-to-right chaining feature as described in the
+-----------------------------------------------+-------------------------------------+
| ``**`` | Exponentiation [#]_ |
+-----------------------------------------------+-------------------------------------+
| ``await`` ``x`` | Await expression |
| :keyword:`await` ``x`` | Await expression |
+-----------------------------------------------+-------------------------------------+
| ``x[index]``, ``x[index:index]``, | Subscription, slicing, |
| ``x(arguments...)``, ``x.attribute`` | call, attribute reference |

View file

@ -127,8 +127,8 @@ Namespace packages
------------------
.. index::
pair:: package; namespace
pair:: package; portion
pair: package; namespace
pair: package; portion
A namespace package is a composite of various :term:`portions <portion>`,
where each portion contributes a subpackage to the parent package. Portions

View file

@ -65,6 +65,7 @@ Comments
--------
.. index:: comment, hash character
single: #; comment
A comment starts with a hash character (``#``) that is not part of a string
literal, and ends at the end of the physical line. A comment signifies the end
@ -78,6 +79,7 @@ Encoding declarations
---------------------
.. index:: source character set, encoding declarations (source file)
single: #; source encoding declaration
If a comment in the first or second line of the Python script matches the
regular expression ``coding[=:]\s*([-\w.]+)``, this comment is processed as an
@ -349,6 +351,9 @@ exactly as written here:
assert del global not with
async elif if or yield
.. index::
single: _, identifiers
single: __, identifiers
.. _id-classes:
Reserved classes of identifiers
@ -395,13 +400,16 @@ Literals
Literals are notations for constant values of some built-in types.
.. index:: string literal, bytes literal, ASCII
single: '; string literal
single: "; string literal
single: u'; string literal
single: u"; string literal
.. _strings:
String and Bytes literals
-------------------------
.. index:: string literal, bytes literal, ASCII
String literals are described by the following lexical definitions:
.. productionlist::
@ -434,6 +442,8 @@ declaration; it is UTF-8 if no encoding declaration is given in the source file;
see section :ref:`encodings`.
.. index:: triple-quoted string, Unicode Consortium, raw string
single: """; string literal
single: '''; string literal
In plain English: Both types of literals can be enclosed in matching single quotes
(``'``) or double quotes (``"``). They can also be enclosed in matching groups
@ -442,11 +452,19 @@ of three single or double quotes (these are generally referred to as
characters that otherwise have a special meaning, such as newline, backslash
itself, or the quote character.
.. index::
single: b'; bytes literal
single: b"; bytes literal
Bytes literals are always prefixed with ``'b'`` or ``'B'``; they produce an
instance of the :class:`bytes` type instead of the :class:`str` type. They
may only contain ASCII characters; bytes with a numeric value of 128 or greater
must be expressed with escapes.
.. index::
single: r'; raw string literal
single: r"; raw string literal
Both string and bytes literals may optionally be prefixed with a letter ``'r'``
or ``'R'``; such strings are called :dfn:`raw strings` and treat backslashes as
literal characters. As a result, in string literals, ``'\U'`` and ``'\u'``
@ -463,6 +481,10 @@ is not supported.
to simplify the maintenance of dual Python 2.x and 3.x codebases.
See :pep:`414` for more information.
.. index::
single: f'; formatted string literal
single: f"; formatted string literal
A string literal with ``'f'`` or ``'F'`` in its prefix is a
:dfn:`formatted string literal`; see :ref:`f-strings`. The ``'f'`` may be
combined with ``'r'``, but not with ``'b'`` or ``'u'``, therefore raw
@ -473,6 +495,19 @@ retained), except that three unescaped quotes in a row terminate the literal. (
"quote" is the character used to open the literal, i.e. either ``'`` or ``"``.)
.. index:: physical line, escape sequence, Standard C, C
single: \; escape sequence
single: \\; escape sequence
single: \a; escape sequence
single: \b; escape sequence
single: \f; escape sequence
single: \n; escape sequence
single: \r; escape sequence
single: \t; escape sequence
single: \v; escape sequence
single: \x; escape sequence
single: \N; escape sequence
single: \u; escape sequence
single: \U; escape sequence
Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in string and
bytes literals are interpreted according to rules similar to those used by
@ -604,6 +639,10 @@ and formatted string literals may be concatenated with plain string literals.
single: string; formatted literal
single: string; interpolated literal
single: f-string
single: {; in formatted string literal
single: }; in formatted string literal
single: !; in formatted string literal
single: :; in formatted string literal
.. _f-strings:
Formatted string literals
@ -738,6 +777,12 @@ actually an expression composed of the unary operator '``-``' and the literal
``1``.
.. index::
single: 0b; integer literal
single: 0o; integer literal
single: 0x; integer literal
single: _; in numeric literal
.. _integers:
Integer literals
@ -778,6 +823,10 @@ Some examples of integer literals::
Underscores are now allowed for grouping purposes in literals.
.. index::
single: .; in numeric literal
single: e; in numeric literal
single: _; in numeric literal
.. _floating:
Floating point literals
@ -806,6 +855,8 @@ Some examples of floating point literals::
Underscores are now allowed for grouping purposes in literals.
.. index::
single: j; in numeric literal
.. _imaginary:
Imaginary literals

View file

@ -112,6 +112,12 @@ unacceptable. The rules observed by various types and the exceptions raised are
given with the definition of the object types (see section :ref:`types`).
.. index:: triple: target; list; assignment
single: ,; in target list
single: *; in assignment target list
single: [; in assignment target list
single: ]; in assignment target list
single: (; in assignment target list
single: ); in assignment target list
Assignment of an object to a target list, optionally enclosed in parentheses or
square brackets, is recursively defined as follows.
@ -321,6 +327,7 @@ Annotated assignment statements
.. index::
pair: annotated; assignment
single: statement; assignment, annotated
single: :; annotated variable
Annotation assignment is the combination, in a single statement,
of a variable or attribute annotation and an optional assignment statement:
@ -372,6 +379,7 @@ The :keyword:`assert` statement
.. index::
statement: assert
pair: debugging; assertions
single: ,; expression list
Assert statements are a convenient way to insert debugging assertions into a
program:
@ -712,6 +720,9 @@ The :keyword:`import` statement
single: module; importing
pair: name; binding
keyword: from
keyword: as
exception: ImportError
single: ,; import statement
.. productionlist::
import_stmt: "import" `module` ["as" `identifier`] ("," `module` ["as" `identifier`])*
@ -761,8 +772,7 @@ available in the local namespace in one of three ways:
.. index::
pair: name; binding
keyword: from
exception: ImportError
single: from; import statement
The :keyword:`from` form uses a slightly more complex process:
@ -786,6 +796,8 @@ Examples::
from foo.bar import baz # foo.bar.baz imported and bound as baz
from foo import attr # foo imported and foo.attr bound as attr
.. index:: single: *; import statement
If the list of identifiers is replaced by a star (``'*'``), all public
names defined in the module are bound in the local namespace for the scope
where the :keyword:`import` statement occurs.
@ -831,7 +843,9 @@ determine dynamically the modules to be loaded.
Future statements
-----------------
.. index:: pair: future; statement
.. index::
pair: future; statement
single: __future__; future statement
A :dfn:`future statement` is a directive to the compiler that a particular
module should be compiled using syntax or semantics that will be available in a
@ -918,6 +932,7 @@ The :keyword:`global` statement
.. index::
statement: global
triple: global; name; binding
single: ,; identifier list
.. productionlist::
global_stmt: "global" `identifier` ("," `identifier`)*
@ -962,6 +977,7 @@ The :keyword:`nonlocal` statement
=================================
.. index:: statement: nonlocal
single: ,; identifier list
.. productionlist::
nonlocal_stmt: "nonlocal" `identifier` ("," `identifier`)*