[Python-Dev] directive statement (PEP 244)
Mon, 16 Jul 2001 19:40:25 +0200
Guido van Rossum wrote:
> > > Martin's hack falls short of doing the right thing in all cases: you
> > > can't have the first statement of your program be "directive = ..."
> > > or "directive(...)".
> > If that is considered as a serious problem, I'll try to solve it with
> > an additional lookahead token: If the next token is a name, then it is
> > a directive.
> MAL seems to want two other changes: directive should be allowed
"allowed" not "required".
> before the module docstring, and it should support the
> syntax from his proto-PEP (directive key = value).
> But MAL and PaulP don't seem to agree on the semantics of this
> directive, and I haven't gotten a good answer why we can't do that
> with a magic comment.
We don't ?
Paul suggested adding encoding directives for 8-bit
strings and comments, but these cannot be used by the Python
compiler in any way and would only be for the benefit of an
editor, so I don't really see the need for them. A programmer
can still add some editor specific comment to the source file
to tell the editor in what encoding to display the file, but this
information is really only useful for the editor, not the
About the magic comment: Unicode literals are translated into
Unicode objects at compile time. The encoding information is
vital for the decoding to succeed. If you place this information
into a comment of the Python source code and have the compiler
depend on it, removing the comment would break your program.
I don't think that's good language design (besides, we already
have enough Unicode magic in Python already...), but then
people may feel different about this.
> In the mean time, I've decided to enable the yield keyword with a
> future statement. In general I now prefer using future statements for
> enabling future features over the directive statement.
> So it's still unclear if we want a directive...
One way or another we need a way to specify compiler parameters
and settings on a per-source file basis. Whether you call it
directive, pragma or magic comment is really secondary and only
a matter of language design.
I've only chosen PEP 244 as basis for the PEP because it seemed
to fit the need. If you decide to go down some other path,
then I'll happily update the PEP to whatever becomes part of
CEO eGenix.com Software GmbH
Consulting & Company: http://www.egenix.com/
Python Software: http://www.lemburg.com/python/