[Python-ideas] Changing optimisation level from a script

Damien George damien.p.george at gmail.com
Tue Sep 13 03:34:29 EDT 2016


Thanks all for the input on this topic.  Let me summarise what was said.

There was discussion that the ability to change the "optimize" value
is not enough and there should be more fine grained control over other
flags/settings.  Perhaps that is true, but at least for our case in
MicroPython there's only one (runtime) optimisation variable and it
mimics CPython's -O command line option (affecting __debug__, assert
compilation, and whether line numbers are included in the bytecode).

Suggestions for setting the opt level were:

1) sys.set_default_optimize(level), with the existing
sys.flags.optimize attribute as the accessor.

2) sys.opt_level, being a read/write attribute

3) sys._setflag(name, value) as implemented by eGenix PyRun

I think option 1 is the most consistent with the existing sys module,
although the name is rather long and I think sys.set_optimize(level)
would be better (after all, none of the other sys.set functions have
the word default in them).

As a second preference I like micropython.opt_level([value]), which
can set and get the value, and keeps it specific to uPy.

Cheers,
Damien.


More information about the Python-ideas mailing list