Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96593ed

Browse files
committed
Continue going through the language reference, bringing it up-to-date.
In particular, document the new comprehensions and remove mentions of long integers. Fix a bunch of related things in the lib ref.
1 parent 44fa8f6 commit 96593ed

7 files changed

Lines changed: 296 additions & 280 deletions

File tree

Doc/library/constants.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Built-in Constants
55
A small number of constants live in the built-in namespace. They are:
66

77

8+
.. note::
9+
10+
:data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be
11+
reassigned, so they can be considered "true" constants.
12+
813
.. XXX False, True, None are keywords too
914
1015
.. data:: False
@@ -37,3 +42,10 @@ A small number of constants live in the built-in namespace. They are:
3742
slicing syntax for user-defined container data types, as in ::
3843

3944
val = container[1:5, 7:10, ...]
45+
46+
47+
.. data:: __debug__
48+
49+
A boolean value that is :data:`True` if Python was not started with the
50+
``-O`` command line option. Its value is used indirectly by the
51+
:keyword:`assert` statement, but it can also be used directly in code.

Doc/library/fileinput.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ The typical use is::
1919
This iterates over the lines of all files listed in ``sys.argv[1:]``, defaulting
2020
to ``sys.stdin`` if the list is empty. If a filename is ``'-'``, it is also
2121
replaced by ``sys.stdin``. To specify an alternative list of filenames, pass it
22-
as the first argument to :func:`input`. A single file name is also allowed.
22+
as the first argument to :func:`.input`. A single file name is also allowed.
2323

2424
All files are opened in text mode by default, but you can override this by
25-
specifying the *mode* parameter in the call to :func:`input` or
25+
specifying the *mode* parameter in the call to :func:`.input` or
2626
:class:`FileInput()`. If an I/O error occurs during opening or reading a file,
2727
:exc:`IOError` is raised.
2828

Doc/library/new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ The :mod:`new` module defines the following functions:
5050

5151
This function returns a new class object, with name *name*, derived from
5252
*baseclasses* (which should be a tuple of classes) and with namespace *dict*.
53-
53+
Alias for the built-in :class:`type`.

Doc/library/readline.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ The :mod:`readline` module defines a number of functions to facilitate
1212
completion and reading/writing of history files from the Python interpreter.
1313
This module can be used directly or via the :mod:`rlcompleter` module. Settings
1414
made using this module affect the behaviour of both the interpreter's
15-
interactive prompt and the prompts offered by the :func:`raw_input` and
16-
:func:`input` built-in functions.
15+
interactive prompt and the prompts offered by the built-in :func:`input`
16+
function.
1717

1818
The :mod:`readline` module defines the following functions:
1919

Doc/reference/executionmodel.rst

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@ Naming and binding
2626
Each occurrence of a name in the program text refers to the :dfn:`binding` of
2727
that name established in the innermost function block containing the use.
2828

29-
.. index:: single: block
29+
.. index:: block
3030

3131
A :dfn:`block` is a piece of Python program text that is executed as a unit.
3232
The following are blocks: a module, a function body, and a class definition.
3333
Each command typed interactively is a block. A script file (a file given as
3434
standard input to the interpreter or specified on the interpreter command line
3535
the first argument) is a code block. A script command (a command specified on
36-
the interpreter command line with the '**-c**' option) is a code block. The string
37-
argument passed to the built-in functions :func:`eval` and :func:`exec` is a
38-
code block. The expression read and evaluated by the built-in function
39-
:func:`input` is a code block.
36+
the interpreter command line with the '**-c**' option) is a code block. The
37+
string argument passed to the built-in functions :func:`eval` and :func:`exec`
38+
is a code block.
4039

4140
.. index:: pair: execution; frame
4241

4342
A code block is executed in an :dfn:`execution frame`. A frame contains some
4443
administrative information (used for debugging) and determines where and how
4544
execution continues after the code block's execution has completed.
4645

47-
.. index:: single: scope
46+
.. index:: scope
4847

4948
A :dfn:`scope` defines the visibility of a name within a block. If a local
5049
variable is defined in a block, its scope includes that block. If the
@@ -61,10 +60,11 @@ scope. The set of all such scopes visible to a code block is called the block's
6160

6261
.. index:: pair: free; variable
6362

64-
If a name is bound in a block, it is a local variable of that block. If a name
65-
is bound at the module level, it is a global variable. (The variables of the
66-
module code block are local and global.) If a variable is used in a code block
67-
but not defined there, it is a :dfn:`free variable`.
63+
If a name is bound in a block, it is a local variable of that block, unless
64+
declared as :keyword:`nonlocal`. If a name is bound at the module level, it is
65+
a global variable. (The variables of the module code block are local and
66+
global.) If a variable is used in a code block but not defined there, it is a
67+
:dfn:`free variable`.
6868

6969
.. index::
7070
single: NameError (built-in exception)
@@ -96,18 +96,20 @@ function definition or at the module level (the top-level code block).
9696

9797
If a name binding operation occurs anywhere within a code block, all uses of the
9898
name within the block are treated as references to the current block. This can
99-
lead to errors when a name is used within a block before it is bound. This rule
99+
lead to errors when a name is used within a block before it is bound. This rule
100100
is subtle. Python lacks declarations and allows name binding operations to
101101
occur anywhere within a code block. The local variables of a code block can be
102102
determined by scanning the entire text of the block for name binding operations.
103103

104-
If the global statement occurs within a block, all uses of the name specified in
105-
the statement refer to the binding of that name in the top-level namespace.
106-
Names are resolved in the top-level namespace by searching the global namespace,
107-
i.e. the namespace of the module containing the code block, and the builtin
108-
namespace, the namespace of the module :mod:`__builtin__`. The global namespace
109-
is searched first. If the name is not found there, the builtin namespace is
110-
searched. The global statement must precede all uses of the name.
104+
If the :keyword:`global` statement occurs within a block, all uses of the name
105+
specified in the statement refer to the binding of that name in the top-level
106+
namespace. Names are resolved in the top-level namespace by searching the
107+
global namespace, i.e. the namespace of the module containing the code block,
108+
and the builtin namespace, the namespace of the module :mod:`__builtin__`. The
109+
global namespace is searched first. If the name is not found there, the builtin
110+
namespace is searched. The global statement must precede all uses of the name.
111+
112+
.. XXX document "nonlocal" semantics here
111113
112114
.. index:: pair: restricted; execution
113115

@@ -137,7 +139,7 @@ block. If the nearest enclosing scope for a free variable contains a global
137139
statement, the free variable is treated as a global.
138140

139141
A class definition is an executable statement that may use and define names.
140-
These references follow the normal rules for name resolution. The namespace of
142+
These references follow the normal rules for name resolution. The namespace of
141143
the class definition becomes the attribute dictionary of the class. Names
142144
defined at the class scope are not visible in methods.
143145

@@ -157,13 +159,14 @@ If the wild card form of import --- ``import *`` --- is used in a function and
157159
the function contains or is a nested block with free variables, the compiler
158160
will raise a :exc:`SyntaxError`.
159161

160-
The :func:`eval` and :func:`exec` functions do
161-
not have access to the full environment for resolving names. Names may be
162-
resolved in the local and global namespaces of the caller. Free variables are
163-
not resolved in the nearest enclosing namespace, but in the global namespace.
164-
[#]_ The :func:`exec` and :func:`eval` functions have optional
165-
arguments to override the global and local namespace. If only one namespace is
166-
specified, it is used for both.
162+
.. XXX from * also invalid with relative imports (at least currently)
163+
164+
The :func:`eval` and :func:`exec` functions do not have access to the full
165+
environment for resolving names. Names may be resolved in the local and global
166+
namespaces of the caller. Free variables are not resolved in the nearest
167+
enclosing namespace, but in the global namespace. [#]_ The :func:`exec` and
168+
:func:`eval` functions have optional arguments to override the global and local
169+
namespace. If only one namespace is specified, it is used for both.
167170

168171

169172
.. _exceptions:
@@ -205,28 +208,24 @@ re-entering the offending piece of code from the top).
205208

206209
When an exception is not handled at all, the interpreter terminates execution of
207210
the program, or returns to its interactive main loop. In either case, it prints
208-
a stack backtrace, except when the exception is :exc:`SystemExit`.
211+
a stack backtrace, except when the exception is :exc:`SystemExit`.
209212

210213
Exceptions are identified by class instances. The :keyword:`except` clause is
211214
selected depending on the class of the instance: it must reference the class of
212215
the instance or a base class thereof. The instance can be received by the
213216
handler and can carry additional information about the exceptional condition.
214217

215-
Exceptions can also be identified by strings, in which case the
216-
:keyword:`except` clause is selected by object identity. An arbitrary value can
217-
be raised along with the identifying string which can be passed to the handler.
218-
219218
.. warning::
220219

221-
Messages to exceptions are not part of the Python API. Their contents may
222-
change from one version of Python to the next without warning and should not be
220+
Exception messages are not part of the Python API. Their contents may change
221+
from one version of Python to the next without warning and should not be
223222
relied on by code which will run under multiple versions of the interpreter.
224223

225224
See also the description of the :keyword:`try` statement in section :ref:`try`
226225
and :keyword:`raise` statement in section :ref:`raise`.
227226

228227
.. rubric:: Footnotes
229228

230-
.. [#] This limitation occurs because the code that is executed by these operations is
231-
not available at the time the module is compiled.
229+
.. [#] This limitation occurs because the code that is executed by these operations
230+
is not available at the time the module is compiled.
232231

0 commit comments

Comments
 (0)