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

Skip to content

Commit 431f0ce

Browse files
committed
Small nits around some of the index entries.
When refering to chapters, use \ref, don't hardcode the chapter number.
1 parent ab03215 commit 431f0ce

1 file changed

Lines changed: 68 additions & 72 deletions

File tree

Doc/ref/ref4.tex

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,56 @@
1-
\chapter{Execution model\label{execmodel}}
1+
\chapter{Execution model \label{execmodel}}
22
\index{execution model}
33

4-
\section{Code blocks, execution frames, and namespaces\label{execframes}}
4+
\section{Code blocks, execution frames, and namespaces \label{execframes}}
55
\index{code block}
6-
\indexii{execution}{frame}
76
\index{namespace}
7+
\indexii{execution}{frame}
88

9-
A \dfn{code block} is a piece of Python program text that can be
10-
executed as a unit, such as a module, a class definition or a function
11-
body. Some code blocks (like modules) are normally executed only once, others
12-
(like function bodies) may be executed many times. Code blocks may
13-
textually contain other code blocks. Code blocks may invoke other
14-
code blocks (that may or may not be textually contained in them) as
15-
part of their execution, e.g., by invoking (calling) a function.
16-
\index{code block}
17-
\indexii{code}{block}
9+
A \dfn{code block}\indexii{code}{block} is a piece
10+
of Python program text that can be executed as a unit, such as a
11+
module, a class definition or a function body. Some code blocks (like
12+
modules) are normally executed only once, others (like function
13+
bodies) may be executed many times. Code blocks may textually contain
14+
other code blocks. Code blocks may invoke other code blocks (that may
15+
or may not be textually contained in them) as part of their execution,
16+
e.g., by invoking (calling) a function.
1817

1918
The following are code blocks: A module is a code block. A function
2019
body is a code block. A class definition is a code block. Each
2120
command typed interactively is a separate code block; a script file (a
2221
file given as standard input to the interpreter or specified on the
2322
interpreter command line the first argument) is a code block; a script
2423
command (a command specified on the interpreter command line with the
25-
`\code{-c}' option) is a code block. The file read by the built-in
24+
`\strong{-c}' option) is a code block. The file read by the built-in
2625
function \function{execfile()} is a code block. The string argument
2726
passed to the built-in function \function{eval()} and to the
2827
\keyword{exec} statement is a code block. And finally, the expression
2928
read and evaluated by the built-in function \function{input()} is a
3029
code block.
3130

3231
A code block is executed in an execution frame. An \dfn{execution
33-
frame} contains some administrative information (used for debugging),
34-
determines where and how execution continues after the code block's
35-
execution has completed, and (perhaps most importantly) defines two
36-
namespaces, the local and the global namespace, that affect
37-
execution of the code block.
38-
\indexii{execution}{frame}
39-
40-
A \dfn{namespace} is a mapping from names (identifiers) to objects.
41-
A particular namespace may be referenced by more than one execution
42-
frame, and from other places as well. Adding a name to a namespace
43-
is called \dfn{binding} a name (to an object); changing the mapping of
44-
a name is called \dfn{rebinding}; removing a name is \dfn{unbinding}.
45-
Namespaces are functionally equivalent to dictionaries (and often
46-
implemented as dictionaries).
47-
\index{namespace}
48-
\indexii{binding}{name}
49-
\indexii{rebinding}{name}
50-
\indexii{unbinding}{name}
51-
52-
The \dfn{local namespace} of an execution frame determines the default
53-
place where names are defined and searched. The \dfn{global
54-
namespace} determines the place where names listed in \keyword{global}
55-
statements are defined and searched, and where names that are not
56-
bound anywhere in the current code block are searched.
57-
\indexii{local}{namespace}
58-
\indexii{global}{namespace}
59-
\stindex{global}
32+
frame}\indexii{execution}{frame} contains some administrative
33+
information (used for debugging), determines where and how execution
34+
continues after the code block's execution has completed, and (perhaps
35+
most importantly) defines two namespaces, the local and the global
36+
namespace, that affect execution of the code block.
37+
38+
A \dfn{namespace}\index{namespace} is a mapping from names
39+
(identifiers) to objects. A particular namespace may be referenced by
40+
more than one execution frame, and from other places as well. Adding
41+
a name to a namespace is called \dfn{binding}\indexii{binding}{name} a
42+
name (to an object); changing the mapping of a name is called
43+
\dfn{rebinding}\indexii{rebinding}{name}; removing a name is
44+
\dfn{unbinding}\indexii{unbinding}{name}. Namespaces are functionally
45+
equivalent to dictionaries (and often implemented as dictionaries).
46+
47+
The \dfn{local namespace}\indexii{local}{namespace} of an execution
48+
frame determines the default place where names are defined and
49+
searched. The
50+
\dfn{global namespace}\indexii{global}{namespace} determines the place
51+
where names listed in \keyword{global}\stindex{global} statements are
52+
defined and searched, and where names that are not bound anywhere in
53+
the current code block are searched.
6054

6155
Whether a name is local or global in a code block is determined by
6256
static inspection of the source text for the code block: in the
@@ -72,31 +66,32 @@ \section{Code blocks, execution frames, and namespaces\label{execframes}}
7266
header. Local names are searched only on the local namespace; global
7367
names are searched only in the global and built-in
7468
namespace.\footnote{
75-
If the code block contains \keyword{exec} statements or the construct
76-
``\samp{from \ldots import *}'', the semantics of local names change:
77-
local name lookup first searches the local namespace, then the global
78-
namespace and the built-in namespace.}
69+
If the code block contains \keyword{exec} statements or the
70+
construct ``\samp{from \ldots import *}'', the semantics of local
71+
names change: local name lookup first searches the local namespace,
72+
then the global namespace and the built-in namespace.}
7973

8074
A target occurring in a \keyword{del} statement is also considered bound
8175
for this purpose (though the actual semantics are to ``unbind'' the
8276
name).
8377

8478
When a global name is not found in the global namespace, it is
8579
searched in the built-in namespace (which is actually the global
86-
namespace of the module \module{__builtin__}). The built-in namespace
87-
associated with the execution of a code block is actually found by
88-
looking up the name \code{__builtins__} is its global namespace; this
89-
should be a dictionary or a module (in the latter case its dictionary
90-
is used). Normally, the \code{__builtins__} namespace is the
91-
dictionary of the built-in module \module{__builtin__} (note: no `s');
92-
if it isn't, restricted execution mode is in effect. When a name is
93-
not found at all, a \exception{NameError} exception is raised.%
94-
\refbimodindex{__builtin__}
80+
namespace of the module
81+
\module{__builtin__}\refbimodindex{__builtin__}). The built-in
82+
namespace associated with the execution of a code block is actually
83+
found by looking up the name \code{__builtins__} is its global
84+
namespace; this should be a dictionary or a module (in the latter case
85+
its dictionary is used). Normally, the \code{__builtins__} namespace
86+
is the dictionary of the built-in module \module{__builtin__} (note:
87+
no `s'); if it isn't, restricted
88+
execution\indexii{restricted}{execution} mode is in effect. When a
89+
name is not found at all, a
90+
\exception{NameError}\withsubitem{(built-in
91+
exception)}{\ttindex{NameError}} exception is raised.
9592
\stindex{from}
9693
\stindex{exec}
9794
\stindex{global}
98-
\indexii{restricted}{execution}
99-
\withsubitem{(built-in exception)}{\ttindex{NameError}}
10095

10196
The following table lists the meaning of the local and global
10297
namespace for various types of code blocks. The namespace for a
@@ -111,10 +106,10 @@ \section{Code blocks, execution frames, and namespaces\label{execframes}}
111106
{n.s. for this module}
112107
{same as global}{}
113108
\lineiv{Script (file or command)}
114-
{n.s. for \module{__main__}}
109+
{n.s. for \module{__main__}\refbimodindex{__main__}}
115110
{same as global}{(1)}
116111
\lineiv{Interactive command}
117-
{n.s. for \module{__main__}}
112+
{n.s. for \module{__main__}\refbimodindex{__main__}}
118113
{same as global}{}
119114
\lineiv{Class definition}
120115
{global n.s. of containing block}
@@ -135,7 +130,6 @@ \section{Code blocks, execution frames, and namespaces\label{execframes}}
135130
{global n.s. of caller}
136131
{local n.s. of caller}{}
137132
\end{tableiv}
138-
\refbimodindex{__main__}
139133

140134
Notes:
141135

@@ -160,22 +154,23 @@ \section{Code blocks, execution frames, and namespaces\label{execframes}}
160154
dictionary representing the current global and local namespace,
161155
respectively. The effect of modifications to this dictionary on the
162156
namespace are undefined.\footnote{
163-
The current implementations return the dictionary actually used to
164-
implement the namespace, \emph{except} for functions, where the
165-
optimizer may cause the local namespace to be implemented differently,
166-
and \function{locals()} returns a read-only dictionary.}
157+
The current implementations return the dictionary actually used to
158+
implement the namespace, \emph{except} for functions, where the
159+
optimizer may cause the local namespace to be implemented
160+
differently, and \function{locals()} returns a read-only
161+
dictionary.}
167162

168-
\section{Exceptions\label{exceptions}}
163+
164+
\section{Exceptions \label{exceptions}}
165+
\index{exception}
169166

170167
Exceptions are a means of breaking out of the normal flow of control
171168
of a code block in order to handle errors or other exceptional
172-
conditions. An exception is \emph{raised} at the point where the error
173-
is detected; it may be \emph{handled} by the surrounding code block or
174-
by any code block that directly or indirectly invoked the code block
175-
where the error occurred.
176-
\index{exception}
177-
\index{raise an exception}
178-
\index{handle an exception}
169+
conditions. An exception is
170+
\emph{raised}\index{raise an exception} at the point where the error
171+
is detected; it may be \emph{handled}\index{handle an exception} by
172+
the surrounding code block or by any code block that directly or
173+
indirectly invoked the code block where the error occurred.
179174
\index{exception handler}
180175
\index{errors}
181176
\index{error handling}
@@ -197,7 +192,8 @@ \section{Exceptions\label{exceptions}}
197192
When an exception is not handled at all, the interpreter terminates
198193
execution of the program, or returns to its interactive main loop. In
199194
either case, it prints a stack backtrace, except when the exception is
200-
\exception{SystemExit}.\ttindex{SystemExit}
195+
\exception{SystemExit}\withsubitem{(built-in
196+
exception)}{\ttindex{SystemExit}}.
201197

202198
Exceptions are identified by string objects or class instances.
203199
Selection of a matching except clause is based on object identity
@@ -215,4 +211,4 @@ \section{Exceptions\label{exceptions}}
215211
being raised.
216212

217213
See also the description of the \keyword{try} and \keyword{raise}
218-
statements in chapter 7.
214+
statements in chapter \ref{compound}.

0 commit comments

Comments
 (0)