From: A.M. K. <aku...@us...> - 2001-03-03 03:23:37
|
Update of /cvsroot/py-howto/pyhowto In directory usw-pr-cvs1:/tmp/cvs-serv26887 Modified Files: python-21.tex Log Message: Discuss PEP 236. Update nested scope section. Index: python-21.tex =================================================================== RCS file: /cvsroot/py-howto/pyhowto/python-21.tex,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** python-21.tex 2001/03/02 21:19:38 1.17 --- python-21.tex 2001/03/03 03:25:04 1.18 *************** *** 91,95 **** variable within a function that contains further function definitions. This seems rather unlikely though, since such code would have been ! pretty confusing to read in the first place. One side effect of the change is that the \code{from \var{module} --- 91,95 ---- variable within a function that contains further function definitions. This seems rather unlikely though, since such code would have been ! pretty confusing to read in the first place. One side effect of the change is that the \code{from \var{module} *************** *** 127,130 **** --- 127,138 ---- poor design anyway). + Compatibility concerns have led to nested scopes being introduced + gradually; in Python 2.1, they aren't enabled by default, but can be + turned on within a module by using a future statement as described in + PEP 236. (See the following section for further discussion of PEP + 236.) In Python 2.2, nested scopes will become the default and there + will be no way to turn them off, but users will have had all of 2.1's + lifetime to fix any breakage resulting from their introduction. + \begin{seealso} *************** *** 137,142 **** %====================================================================== \section{PEP 236: \module{__future__} Directives} ! XXX %====================================================================== --- 145,177 ---- %====================================================================== \section{PEP 236: \module{__future__} Directives} + + The reaction to nested scopes was widespread concern about the dangers + of breaking code with the 2.1 release, and it was strong enough to + make the Pythoneers take a more conservative approach. This approach + consists of introducing a convention for enabling optional + functionality in release N that will become compulsory in release N+1. + + The syntax uses a \code{from...import} statement using the reserved + module name \module{__future__}. Nested scopes can be enabled by the + following statement: + + \begin{verbatim} + from __future__ import nested_scopes + \end{verbatim} ! While it looks like a normal \keyword{import} statement, it's not; ! there are strict rules on where such a future statement can be put. ! They can only be at the top of a module, and must precede any Python ! code or regular \keyword{import} statements. This is because such ! statements can affect how the Python bytecode compiler parses code and ! generates bytecode, so they must precede any statement that will ! result in bytecodes being produced. ! ! \begin{seealso} ! ! \seepep{236}{Back to the \module{__future__}}{Written by Tim Peters, ! and primarily implemented by Jeremy Hylton.} ! ! \end{seealso} %====================================================================== |