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