circuitpython/tests/micropython/viper_globals.py

23 lines
328 B
Python
Raw Normal View History

# test that viper functions capture their globals context
gl = {}
2021-04-20 01:22:44 -04:00
exec(
"""
@micropython.viper
def f():
return x
2021-04-20 01:22:44 -04:00
""",
gl,
)
# x is not yet in the globals, f should not see it
try:
2021-04-20 01:22:44 -04:00
print(gl["f"]())
except NameError:
2021-04-20 01:22:44 -04:00
print("NameError")
# x is in globals, f should now see it
2021-04-20 01:22:44 -04:00
gl["x"] = 123
print(gl["f"]())