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
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
print(globals()["X"])
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# function name that matches a constant
|
|
|
|
def X():
|
|
|
|
print("function X", X)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
globals()["X"]()
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# arguments that match a constant
|
|
|
|
def f(X, *Y, **Z):
|
|
|
|
pass
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
f(1)
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# class name that matches a constant
|
|
|
|
class X:
|
|
|
|
def f(self):
|
|
|
|
print("class X", X)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
globals()["X"]().f()
|
|
|
|
|
2023-02-01 19:51:48 -05:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
# constant within a class
|
|
|
|
class A:
|
|
|
|
C1 = const(4)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
def X(self):
|
|
|
|
print("method X", Y, C1, self.C1)
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
A().X()
|