[Python-ideas] Changing optimisation level from a script
Petr Viktorin
encukou at gmail.com
Sat Sep 10 04:23:10 EDT 2016
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 it would be good to discuss
> with upstream (ie python-dev/python-ideas) about adding new
> functions/classes so that MicroPython doesn't diverge too much (eg
> Paul Sokolovsky had a discussion about time.sleep_ms, time.sleep_us
> etc, which was fruitful). sys.optimize(value) is a pretty simple
> addition so I thought it would be a straight forward discussion to
> have here.
>
> 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 want to push CPython to actually add such a thing
> if it's not seen as a useful addition. Instead I want to see how
> others would implement it if they needed to.
Hello,
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 this was added to the stdlib, I'd expect it to use a
property, e.g.
pin.value = 1
result = pin.value
I was wondering, what's the story of this aspect of MicroPython API?
Does it have hidden advantages? Were you inspired by another library? Or
was it just the easiest way to get the functionality (I assume you
implemented functions before properties), and then it stuck?
More information about the Python-ideas
mailing list