791b65f4b2
Having a micropython.const identity function, and writing "from micropython import const" at the start of scripts that use the const feature, allows to write scripts which are compatible with CPython, and with uPy builds that don't include const optimisation. This patch adds such a function and updates the tests to do the import.
26 lines
302 B
Python
26 lines
302 B
Python
# test constant optimisation
|
|
|
|
from micropython import const
|
|
|
|
X = const(123)
|
|
Y = const(X + 456)
|
|
|
|
print(X, Y + 1)
|
|
|
|
def f():
|
|
print(X, Y + 1)
|
|
|
|
f()
|
|
|
|
_X = const(12)
|
|
_Y = const(_X + 34)
|
|
|
|
print(_X, _Y)
|
|
|
|
class A:
|
|
Z = const(1)
|
|
_Z = const(2)
|
|
print(Z, _Z)
|
|
|
|
print(hasattr(A, 'Z'), hasattr(A, '_Z'))
|