Compiler directives in the source
A. Lloyd Flanagan
alloydflanagan at attbi.com
Wed Feb 5 17:49:23 EST 2003
Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> wrote in message news:<u4g24vs1ah54s0sqnbjc1o1c6bds3u6rm5 at 4ax.com>...
> The earlier discussion on coding directives in comments got me
> thinking.
>
>
> I think the following compiler options would be usefully avilable as
> directives in the source as well as on the command line:
>
> -O : optimize generated bytecode
> -OO : remove doc-strings in addition to the -O optimizations
> -Q arg : division options:
> -S : don't imply 'import site' on initialization
> -v : verbose (trace import statements) (also PYTHONVERBOSE=x)
> -W arg : warning control
> -x : skip first line of source
>
> To that list, I would like to add:
>
> debug arg : control value of __debug__ and assert() (independent of
> optimisation)
...
> That would give us a set of compiler directives like these:
>
> %optimize off | on | full
> %division old | warn |new
> %importsite off | on
> %verbose off | on
> %warnings arg
> %skip 1
> %debug off | on
> %ignorecase off | on (like PYTHONCASEOK)
> %path dir;dir... (like PYTHONPATH)
> %home dir (like PYTHONHOME)
>
FWIW, I like the idea for setting global options for the file (much
better than magic comments). I don't like the idea for things like
'conditional compilation' or skipping lines; that to me just adds a
new complexity on top of existing features. If people start using
these directives like the compiler directives in C, we'll have the
same problems with them that C has.
I'd also suggest they be required to be placed before any code in the
file; since they're meta-directives they shouldn't get mixed with
code, again for readability.
More information about the Python-list
mailing list