tests/basics: Add tests for __name__ and __globals__ attrs on closures.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-06-24 23:34:15 +10:00
parent d68532558d
commit 268ec1e3eb
2 changed files with 17 additions and 0 deletions

View File

@ -19,3 +19,18 @@ try:
foo.__globals__ = None
except AttributeError:
print("AttributeError")
# test closures have the __globals__ attribute
def outer():
x = 1
def inner():
return x
return inner
print(outer.__globals__ is globals())
print(outer().__globals__ is globals())

View File

@ -24,9 +24,11 @@ except AttributeError:
pass
# name of a function that has closed over variables
# and also the name of the inner closure
def outer():
x = 1
def inner():
return x
return inner
print(outer.__name__)
print(outer().__name__)