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

Skip to content

Commit 8bea5dc

Browse files
committed
Move future statement here from appendix a.
1 parent 3cfe754 commit 8bea5dc

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Doc/ref/ref6.tex

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,84 @@ \section{The \keyword{import} statement \label{import}}
738738
information.
739739
\bifuncindex{__import__}
740740
741+
\subsection{Future statements \label{future}}
742+
743+
A \dfn{future statement}\indexii{future}{statement} is a directive to
744+
the compiler that a particular module should be compiled using syntax
745+
or semantics that will be available in a specified future release of
746+
Python. The future statement is intended to ease migration to future
747+
versions of Python that introduce incompatible changes to the
748+
language. It allows use of the new features on a per-module basis
749+
before the release in which the feature becomes standard.
750+
751+
\begin{productionlist}[*]
752+
\production{future_statement}
753+
{"from" "__future__" "import" feature ["as" name]}
754+
\productioncont{("," feature ["as" name])*}
755+
\production{feature}{identifier}
756+
\production{name}{identifier}
757+
\end{productionlist}
758+
759+
A future statement must appear near the top of the module. The only
760+
lines that can appear before a future statement are:
761+
762+
\begin{itemize}
763+
764+
\item the module docstring (if any),
765+
\item comments,
766+
\item blank lines, and
767+
\item other future statements.
768+
769+
\end{itemize}
770+
771+
The features recognized by Python 2.3 are \samp{generators},
772+
\samp{division} and \samp{nested_scopes}. \samp{generators} and
773+
\samp{nested_scopes} are redundant in 2.3 because they are always
774+
enabled.
775+
776+
A future statement is recognized and treated specially at compile
777+
time: Changes to the semantics of core constructs are often
778+
implemented by generating different code. It may even be the case
779+
that a new feature introduces new incompatible syntax (such as a new
780+
reserved word), in which case the compiler may need to parse the
781+
module differently. Such decisions cannot be pushed off until
782+
runtime.
783+
784+
For any given release, the compiler knows which feature names have been
785+
defined, and raises a compile-time error if a future statement contains
786+
a feature not known to it.
787+
788+
The direct runtime semantics are the same as for any import statement:
789+
there is a standard module \module{__future__}, described later, and
790+
it will be imported in the usual way at the time the future statement
791+
is executed.
792+
793+
The interesting runtime semantics depend on the specific feature
794+
enabled by the future statement.
795+
796+
Note that there is nothing special about the statement:
797+
798+
\begin{verbatim}
799+
import __future__ [as name]
800+
\end{verbatim}
801+
802+
That is not a future statement; it's an ordinary import statement with
803+
no special semantics or syntax restrictions.
804+
805+
Code compiled by an exec statement or calls to the builtin functions
806+
\function{compile()} and \function{execfile()} that occur in a module
807+
\module{M} containing a future statement will, by default, use the new
808+
syntax or semantics associated with the future statement. This can,
809+
starting with Python 2.2 be controlled by optional arguments to
810+
\function{compile()} --- see the documentation of that function in the
811+
library reference for details.
812+
813+
A future statement typed at an interactive interpreter prompt will
814+
take effect for the rest of the interpreter session. If an
815+
interpreter is started with the \programopt{-i} option, is passed a
816+
script name to execute, and the script includes a future statement, it
817+
will be in effect in the interactive session started after the script
818+
is executed.
741819
742820
\section{The \keyword{global} statement \label{global}}
743821
\stindex{global}

0 commit comments

Comments
 (0)