A counter-proposal to __future__ in PEP 236
Martin von Loewis
loewis at informatik.hu-berlin.de
Thu Mar 1 06:00:23 EST 2001
To selectively activate nested scopes in Python 2.1, PEP 236 proposes
the "future" statement. That means that you have to write
from __future__ import nested_scopes
Even though this looks like an import statement, it is not: instead,
it changes the meaning of variable binding in the presence of nested
functions.
I personally consider this a confusing notation, and propose a
different syntax, which would read
directive nested_scopes
The directive statement currently only supports activating nested
scopes, but it may get further use later, e.g. to activate
case-insensitivity or set the source file character set.
A patch implementing the directive statement is at
http://sourceforge.net/tracker/index.php?func=detail&aid=404997&group_id=5470&atid=305470
In this implementation, directive is only considered as a keyword if
it appears at the beginning of the module. Therefore, code that
happens to use directive as an identifier will not break (unless it
assigns to directive as the first thing in the module).
I'd appreciate any comments as to whether this directive statement is
better or worse for the purpose of indicating that nested scopes are
used in a module.
Please note that making nested scopes the default in a major release
after 2.1 is an unrelated issue: it can happen with either future
statements or directives; when it happens, both the future statement
and the directive can continue to work (although they would be
unnecessary); tools could automatically remove unnessary directives if
desired.
Regards,
Martin
More information about the Python-list
mailing list