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

Signed-off-by: Damien George <damien@micropython.org>
pull/8814/head
Damien George 2022-06-24 23:34:15 +10:00
rodzic d68532558d
commit 268ec1e3eb
2 zmienionych plików z 17 dodań i 0 usunięć

Wyświetl plik

@ -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())

Wyświetl plik

@ -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__)