mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 20:50:14 +01:00
py/modmicropython: Add micropython.const, alias for identity function.
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.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# test constant optimisation
|
||||
|
||||
from micropython import const
|
||||
|
||||
X = const(123)
|
||||
Y = const(X + 456)
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# check that consts are not replaced in anything except standalone identifiers
|
||||
|
||||
from micropython import const
|
||||
|
||||
X = const(1)
|
||||
Y = const(2)
|
||||
Z = const(3)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# make sure syntax error works correctly for bad const definition
|
||||
|
||||
from micropython import const
|
||||
|
||||
def test_syntax(code):
|
||||
try:
|
||||
exec(code)
|
||||
|
||||
Reference in New Issue
Block a user