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