Re: [Python-ideas] Changing optimisation level from a script

2016-09-13 Thread Nick Coghlan
On 13 September 2016 at 17:34, Damien George wrote: > 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 impleme

Re: [Python-ideas] Changing optimisation level from a script

2016-09-13 Thread Damien George
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

Re: [Python-ideas] Changing optimisation level from a script

2016-09-13 Thread Damien George
Hi Petr, > The API you proposed here comes is similar to something I see a lot in > MicroPython libraries: functions/methods that combine a getter and setter. > For example, to set the value on a pin, you do: > pin.value(1) > and to read, you do: > result = pin.value() > > If an API like

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread M.-A. Lemburg
In eGenix PyRun we expose a new helper in the sys module for this: --- ./Python/sysmodule.c 2015-12-07 02:39:11.0 +0100 +++ ./Python/sysmodule.c2016-05-03 19:22:35.793193862 +0200 @@ -1205,6 +1205,50 @@ Return True if Python is exiting."); +/*** PyRun Extension *

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread Brett Cannon
If people are curious as to where import makes its decision as to what bytecode to load based on the optimization level, see https://github.com/python/cpython/blob/ad3b9aeaab5122b22445f9120a6ccdc1987c15cc/Lib/importlib/_bootstrap_external.py#L292 . On Sat, 10 Sep 2016 at 04:53 Nick Coghlan wrote

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread Nick Coghlan
On 10 September 2016 at 03:20, Brett Cannon wrote: > I don't know if it's been discussed, but I have thought about it in context > of PEP 511. The problem with swapping optimization levels post-start is that > you end up with inconsistencies, e.g. asserts that depend on other > asserts/__debug__ t

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread Ivan Levkivskyi
On 10 September 2016 at 03:01, Steven D'Aprano wrote: > In particular, I expect that some time soon somebody will propose at > least one more optimization: > > - remove annotations > > In process of developing the implementation of variable annotations this idea already appeared (I even did some

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread Petr Viktorin
On 09/10/2016 02:04 AM, Damien George wrote: What is to stop you from adding this to micropython as a library extension? That's what I would like to do, and usually we do just go ahead and add our own extensions, trying to be Pythonic as possible :) But we do that a lot and sometimes I think i

Re: [Python-ideas] Changing optimisation level from a script

2016-09-10 Thread Victor Stinner
2016-09-10 2:56 GMT-04:00 Andrew Svetlov : > There are also peephole optimization. > Removing it may prevent false positives for coverage tool > http://bugs.python.org/issue2506 My PEP 511 adds "-o noopt" to disable the peephole optimizer ;-) "PEP 511 -- API for code transformers" www.python.org/

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Andrew Svetlov
There are also peephole optimization. Removing it may prevent false positives for coverage tool http://bugs.python.org/issue2506 On Sat, Sep 10, 2016 at 4:01 AM Steven D'Aprano wrote: > On Sat, Sep 10, 2016 at 10:04:46AM +1000, Damien George wrote: > > > I guess my main question to this list is:

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Steven D'Aprano
On Sat, Sep 10, 2016 at 10:04:46AM +1000, Damien George wrote: > I guess my main question to this list is: if CPython were to add a > function to change the optimisation level at runtime, what would it > look like? I don't think it would look like sys.optimize(flag). At the very least, it would

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread MRAB
On 2016-09-10 01:04, Damien George wrote: What is to stop you from adding this to micropython as a library extension? That's what I would like to do, and usually we do just go ahead and add our own extensions, trying to be Pythonic as possible :) But we do that a lot and sometimes I think it w

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Damien George
> What is to stop you from adding this to micropython as a library > extension? That's what I would like to do, and usually we do just go ahead and add our own extensions, trying to be Pythonic as possible :) But we do that a lot and sometimes I think it would be good to discuss with upstream (ie

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Guido van Rossum
I very much doubt that one assert might depend on another, and if they do, we can just tell people not to change the debug level. The API to change this should set __debug__ appropriately. On Fri, Sep 9, 2016 at 10:20 AM, Brett Cannon wrote: > > > On Thu, 8 Sep 2016 at 21:36 Damien George wrote:

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Brett Cannon
On Thu, 8 Sep 2016 at 21:36 Damien George wrote: > Hi all, > > When starting CPython from the command line you can pass the -O option > to enable optimisations (eg `assert 0` won't raise an exception when > -O is passed). But, AFAIK, there is no way to change the optimisation > level after the i

Re: [Python-ideas] Changing optimisation level from a script

2016-09-09 Thread Guido van Rossum
What is to stop you from adding this to micropython as a library extension? I've never felt the urge to do this and I don't think I've ever heard it requested before. If you think it should be in the stdlib, given the timing of the 3.6 feature freeze the earliest time it could land would be Python