circuitpython/tests/micropython/const2.py

49 lines
637 B
Python
Raw Normal View History

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