2016-09-26 23:03:53 -04:00
|
|
|
# check that consts are not replaced in anything except standalone identifiers
|
|
|
|
|
2016-09-26 23:34:21 -04:00
|
|
|
from micropython import const
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
X = const(1)
|
|
|
|
Y = const(2)
|
|
|
|
Z = const(3)
|
|
|
|
|
|
|
|
# import that uses a constant
|
|
|
|
import micropython as X
|
2021-03-15 09:57:36 -04:00
|
|
|
|
|
|
|
print(globals()["X"])
|
2016-09-26 23:03:53 -04:00
|
|
|
|
2023-02-01 03:08:41 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# function name that matches a constant
|
|
|
|
def X():
|
2021-03-15 09:57:36 -04:00
|
|
|
print("function X", X)
|
|
|
|
|
|
|
|
|
|
|
|
globals()["X"]()
|
2016-09-26 23:03:53 -04:00
|
|
|
|
2023-02-01 03:08:41 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# arguments that match a constant
|
|
|
|
def f(X, *Y, **Z):
|
|
|
|
pass
|
2021-03-15 09:57:36 -04:00
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
f(1)
|
|
|
|
|
2023-02-01 03:08:41 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# class name that matches a constant
|
|
|
|
class X:
|
|
|
|
def f(self):
|
2021-03-15 09:57:36 -04:00
|
|
|
print("class X", X)
|
|
|
|
|
|
|
|
|
|
|
|
globals()["X"]().f()
|
2016-09-26 23:03:53 -04:00
|
|
|
|
2023-02-01 03:08:41 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# constant within a class
|
|
|
|
class A:
|
|
|
|
C1 = const(4)
|
2021-03-15 09:57:36 -04:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
def X(self):
|
2021-03-15 09:57:36 -04:00
|
|
|
print("method X", Y, C1, self.C1)
|
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
A().X()
|