1- \chapter {Appendix: Future statements and nested scopes }
1+ \chapter {Future statements and nested scopes \label {futures } }
2+ \sectionauthor {Jeremy Hylton}{
[email protected] }
3+
24
35The semantics of Python's static scoping will change in version 2.2 to
46support resolution of unbound local names in enclosing functions'
57namespaces. The new semantics will be available in Python 2.1 through
6- the use of a future statement. This appendix documents these two
8+ the use of a `` future'' statement. This appendix documents these two
79features for Python 2.1; it will be removed in Python 2.2 and the
810features will be documented in the main sections of this manual.
911
10- \section {Future statements }
11- \indexii {future}{statement}
1212
13- A \dfn {future statement} is a directive to the compiler that a
14- particular module should be compiled using syntax or semantics that
15- will be available in a specified future release of Python. The future
16- statement is intended to ease migration to future versions of Python
17- that introduce incompatible changes to the language. It allows use of
18- the new features on a per-module basis before the release in which the
19- feature becomes standard.
13+ \section {Future statements \label {future-statements } }
14+
15+ A \dfn {future statement}\indexii {future}{statement} is a directive to
16+ the compiler that a particular module should be compiled using syntax
17+ or semantics that will be available in a specified future release of
18+ Python. The future statement is intended to ease migration to future
19+ versions of Python that introduce incompatible changes to the
20+ language. It allows use of the new features on a per-module basis
21+ before the release in which the feature becomes standard.
2022
2123\begin {verbatim }
2224future_statement: "from" "__future__" "import" feature ["as" name]
@@ -52,7 +54,7 @@ \section{Future statements}
5254a feature not known to it.
5355
5456The direct runtime semantics are the same as for any import statement:
55- there is a standard module \file {__future__.py }, described later, and
57+ there is a standard module \module {__future__}, described later, and
5658it will be imported in the usual way at the time the future statement
5759is executed.
5860
@@ -65,28 +67,28 @@ \section{Future statements}
6567import __future__ [as name]
6668\end {verbatim }
6769
68- That is not a future statement; it's an ordinary import statement, with
70+ That is not a future statement; it's an ordinary import statement with
6971no special semantics or syntax restrictions.
7072
7173Code compiled by an exec statement or calls to the builtin functions
72- \function {compile} and \function {execfile} that occur in a module M
73- containing a future statement will use the new syntax or semantics
74- associated with the future statement.
74+ \function {compile() } and \function {execfile() } that occur in a module
75+ \module {M} containing a future statement will use the new syntax or
76+ semantics associated with the future statement.
7577
7678A future statement typed at an interactive interpreter prompt will
7779take effect for the rest of the interpreter session. If an
78- interpreter is started with the \emph {-i } option, is passed a
80+ interpreter is started with the \programopt {-i} option, is passed a
7981script name to execute, and the script includes a future statement, it
8082will be in effect in the interactive session started after the script
8183is executed.
8284
8385\section {\module {__future__} ---
8486 Future statement definitions }
8587
86- \declaremodule {standard}{__future__}
88+ \declaremodule [future] {standard}{__future__}
8789\modulesynopsis {Future statement definitions}
8890
89- \file {__future__.py } is a real module, and serves three purposes:
91+ \module {__future__} is a real module, and serves three purposes:
9092
9193\begin {itemize }
9294
@@ -95,13 +97,13 @@ \section{\module{__future__} ---
9597
9698\item To ensure that future_statements run under releases prior to 2.1
9799 at least yield runtime exceptions (the import of
98- \code {__future__} will fail, because there was no module of
100+ \module {__future__} will fail, because there was no module of
99101 that name prior to 2.1).
100102
101103\item To document when incompatible changes were introduced, and when they
102104 will be --- or were --- made mandatory. This is a form of executable
103105 documentation, and can be inspected programatically via importing
104- \code {__future__} and examining its contents.
106+ \module {__future__} and examining its contents.
105107
106108\end {itemize }
107109
@@ -111,8 +113,8 @@ \section{\module{__future__} ---
111113FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ")"
112114\end {verbatim }
113115
114- where, normally, OptionalRelease < MandatoryRelease, and both are
115- 5-tuples of the same form as \code {sys.version_info}:
116+ where, normally, OptionalRelease is less then MandatoryRelease, and
117+ both are 5-tuples of the same form as \code {sys.version_info}:
116118
117119\begin {verbatim }
118120 (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
@@ -135,15 +137,17 @@ \section{\module{__future__} ---
135137future statement to use the feature in question, but may continue to
136138use such imports.
137139
138- MandatoryRelease may also be None, meaning that a planned feature got
139- dropped.
140+ MandatoryRelease may also be \code { None} , meaning that a planned
141+ feature got dropped.
140142
141143Instances of class \class {_Feature} have two corresponding methods,
142- \member {getOptionalRelease()} and \member {getMandatoryRelease()}.
144+ \method {getOptionalRelease()} and \method {getMandatoryRelease()}.
145+
146+ No feature description will ever be deleted from \module {__future__}.
147+
143148
144- No feature line will ever be deleted from \file {__future__.py}.
149+ \section { Nested scopes \label { nested-scopes } }
145150
146- \section {Nested scopes }
147151\indexii {nested}{scopes}
148152
149153Nested scopes are left as an exercise for the reader.
0 commit comments