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
|
|
|
|
|
|
|
print(globals()["X"])
|
2016-09-26 23:03:53 -04:00
|
|
|
|
|
|
|
# function name that matches a constant
|
|
|
|
def X():
|
2020-03-22 22:26:08 -04:00
|
|
|
print("function X", X)
|
|
|
|
|
|
|
|
|
|
|
|
globals()["X"]()
|
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)
|
|
|
|
|
|
|
|
# class name that matches a constant
|
|
|
|
class X:
|
|
|
|
def f(self):
|
2020-03-22 22:26:08 -04:00
|
|
|
print("class X", X)
|
|
|
|
|
|
|
|
|
|
|
|
globals()["X"]().f()
|
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):
|
2020-03-22 22:26:08 -04:00
|
|
|
print("method X", Y, C1, self.C1)
|
|
|
|
|
|
|
|
|
2016-09-26 23:03:53 -04:00
|
|
|
A().X()
|