New PEP: The directive statement

Martin von Loewis loewis at informatik.hu-berlin.de
Tue Mar 20 15:14:55 EST 2001


"Clark C. Evans" <cce at clarkevans.com> writes:

> >     Introducing 'directive' as a new keyword might cause
> >     incompatibilities with existing code. Following the guideline in
> >     [1], in the initial implementation of this specification,
> >     directive is a new keyword only if it was used in a valid
> >     directive_statement (i.e. if it appeared as the first non-string
> >     token in a module).
> 
> I'm new to python, but why not have the module have a built-in
> set of directives as a list?  As this could then be an attribute
> of many different objects, including modules.
> 
> __directives__ = { 'transitional', 'nested-scopes' }

The main problem is that the intended use really is not for run-time
semantics, i.e. the interpreter won't dynamically look at
__directives__ and do magic things. Instead, it is meant as a
"compile-time" thing, i.e. with effects when the source code is
interpreted. In that sense, it is the second declaration in python
(after global); normally, Python statements are actions (including def
and class).

That is also why the PEP 236 proposal (__future__ imports) finds that
much resistance: it uses an action statement to declare things.

Regards,
Martin

P.S. If "directive transitional nested_scopes" is approved, an
interesting observation is that all Python declarations deal with
variable visibility and name binding.



More information about the Python-list mailing list