diff options
Diffstat (limited to 'Doc/reference')
| -rw-r--r-- | Doc/reference/compound_stmts.rst | 8 | ||||
| -rw-r--r-- | Doc/reference/datamodel.rst | 5 | ||||
| -rw-r--r-- | Doc/reference/executionmodel.rst | 4 | ||||
| -rw-r--r-- | Doc/reference/expressions.rst | 16 | ||||
| -rw-r--r-- | Doc/reference/simple_stmts.rst | 26 |
5 files changed, 32 insertions, 27 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 31ae0ed..d261574 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -352,6 +352,8 @@ The execution of the :keyword:`with` statement with one "item" proceeds as follo #. The context expression (the expression given in the :token:`with_item`) is evaluated to obtain a context manager. +#. The context manager's :meth:`__exit__` is loaded for later use. + #. The context manager's :meth:`__enter__` method is invoked. #. If a target was included in the :keyword:`with` statement, the return value @@ -361,9 +363,9 @@ The execution of the :keyword:`with` statement with one "item" proceeds as follo The :keyword:`with` statement guarantees that if the :meth:`__enter__` method returns without an error, then :meth:`__exit__` will always be - called. Thus, if an error occurs during the assignment to the target - list, it will be treated the same as an error occurring within the suite - would be. See step 5 below. + called. Thus, if an error occurs during the assignment to the target list, + it will be treated the same as an error occurring within the suite would + be. See step 6 below. #. The suite is executed. diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 6f874b6..129f987 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1218,8 +1218,7 @@ Basic customization Arguments to rich comparison methods are never coerced. To automatically generate ordering operations from a single root operation, - see the `Total Ordering recipe in the ASPN cookbook - <http://code.activestate.com/recipes/576529/>`_\. + see :func:`functools.total_ordering`. .. method:: object.__hash__(self) @@ -1595,7 +1594,7 @@ attributes of *A* as they are defined within the body of the class statement. Once those definitions are executed, the ordered dictionary is fully populated and the metaclass's :meth:`__new__` method gets invoked. That method builds the new type and it saves the ordered dictionary keys in an attribute -called *members*. +called ``members``. Customizing instance and subclass checks diff --git a/Doc/reference/executionmodel.rst b/Doc/reference/executionmodel.rst index d11e741..82e37a2 100644 --- a/Doc/reference/executionmodel.rst +++ b/Doc/reference/executionmodel.rst @@ -94,9 +94,7 @@ module, except those beginning with an underscore. This form may only be used at the module level. A target occurring in a :keyword:`del` statement is also considered bound for -this purpose (though the actual semantics are to unbind the name). It is -illegal to unbind a name that is referenced by an enclosing scope; the compiler -will report a :exc:`SyntaxError`. +this purpose (though the actual semantics are to unbind the name). Each assignment or import statement occurs within a block defined by a class or function definition or at the module level (the top-level code block). diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 944c39f..f882952 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -651,7 +651,7 @@ the call. An implementation may provide built-in functions whose positional parameters do not have names, even if they are 'named' for the purpose of documentation, and which therefore cannot be supplied by keyword. In CPython, this is the - case for functions implemented in C that use :cfunc:`PyArg_ParseTuple` to + case for functions implemented in C that use :c:func:`PyArg_ParseTuple` to parse their arguments. If there are more positional arguments than there are formal parameter slots, a @@ -921,6 +921,11 @@ the left or right by the number of bits given by the second argument. A right shift by *n* bits is defined as division by ``pow(2,n)``. A left shift by *n* bits is defined as multiplication with ``pow(2,n)``. +.. note:: + + In the current implementation, the right-hand operand is required + to be at most :attr:`sys.maxsize`. If the right-hand operand is larger than + :attr:`sys.maxsize` an :exc:`OverflowError` exception is raised. .. _bitwise: @@ -958,9 +963,9 @@ must be integers. .. _comparisons: .. _is: -.. _isnot: +.. _is not: .. _in: -.. _notin: +.. _not in: Comparisons =========== @@ -1156,11 +1161,9 @@ not bother to return a value of the same type as its argument, so e.g., ``not 'foo'`` yields ``False``, not ``''``.) -Conditional Expressions +Conditional expressions ======================= -.. versionadded:: 2.5 - .. index:: pair: conditional; expression pair: ternary; operator @@ -1309,6 +1312,7 @@ groups from right to left). | ``(expressions...)``, | Binding or tuple display, | | ``[expressions...]``, | list display, | | ``{key:datum...}``, | dictionary display, | +| ``{expressions...}`` | set display | +-----------------------------------------------+-------------------------------------+ diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index 548e0a9..a375117 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -385,11 +385,6 @@ namespace, depending on whether the name occurs in a :keyword:`global` statement in the same code block. If the name is unbound, a :exc:`NameError` exception will be raised. -.. index:: pair: free; variable - -It is illegal to delete a name from the local namespace if it occurs as a free -variable in a nested block. - .. index:: pair: attribute; deletion Deletion of attribute references, subscriptions and slicings is passed to the @@ -397,6 +392,11 @@ primary object involved; deletion of a slicing is in general equivalent to assignment of an empty slice of the right type (but even this is determined by the sliced object). +.. versionchanged:: 3.2 + + Previously it was illegal to delete a name from the local namespace if it + occurs as a free variable in a nested block. + .. _return: @@ -674,7 +674,9 @@ Once the name of the module is known (unless otherwise specified, the term "module" will refer to both packages and modules), searching for the module or package can begin. The first place checked is :data:`sys.modules`, the cache of all modules that have been imported -previously. If the module is found there then it is used in step (2) of import. +previously. If the module is found there then it is used in step (2) of import +unless ``None`` is found in :data:`sys.modules`, in which case +:exc:`ImportError` is raised. .. index:: single: sys.meta_path @@ -691,7 +693,7 @@ within a package (as denoted by the existence of a dot in the name), then a second argument to :meth:`find_module` is given as the value of the :attr:`__path__` attribute from the parent package (everything up to the last dot in the name of the module being imported). If a finder can find the module -it returns a :term:`loader` (discussed later) or returns :keyword:`None`. +it returns a :term:`loader` (discussed later) or returns ``None``. .. index:: single: sys.path_hooks @@ -718,11 +720,11 @@ finder cached then :data:`sys.path_hooks` is searched by calling each object in the list with a single argument of the path, returning a finder or raises :exc:`ImportError`. If a finder is returned then it is cached in :data:`sys.path_importer_cache` and then used for that path entry. If no finder -can be found but the path exists then a value of :keyword:`None` is +can be found but the path exists then a value of ``None`` is stored in :data:`sys.path_importer_cache` to signify that an implicit, file-based finder that handles modules stored as individual files should be used for that path. If the path does not exist then a finder which always -returns :keyword:`None` is placed in the cache for the path. +returns ``None`` is placed in the cache for the path. .. index:: single: loader @@ -786,7 +788,7 @@ first form of :keyword:`import`, an alternate local name can be supplied by specifying ":keyword:`as` localname". If a name is not found, :exc:`ImportError` is raised. If the list of identifiers is replaced by a star (``'*'``), all public names defined in the module are bound in the local -namespace of the :keyword:`import` statement.. +namespace of the :keyword:`import` statement. .. index:: single: __all__ (optional module attribute) @@ -818,7 +820,7 @@ leading dot means the current package where the module making the import exists. Two dots means up one package level. Three dots is up two levels, etc. So if you execute ``from . import mod`` from a module in the ``pkg`` package then you will end up importing ``pkg.mod``. If you execute ``from ..subpkg2 -imprt mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``. +import mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``. The specification for relative imports is contained within :pep:`328`. :func:`importlib.import_module` is provided to support applications that @@ -944,7 +946,7 @@ definition, function definition, or :keyword:`import` statement. **Programmer's note:** the :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 -object supplied to the builtin :func:`exec` function does not affect the 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 call. The same applies to the :func:`eval` and :func:`compile` functions. |
