8000 tests/basics: Add tests for __name__ and __globals__ attrs on closures. · DucRP/micropython@268ec1e · GitHub
[go: up one dir, main page]

Skip to content

Commit 268ec1e

Browse files
committed
tests/basics: Add tests for __name__ and __globals__ attrs on closures.
Signed-off-by: Damien George <damien@micropython.org>
1 parent d685325 commit 268ec1e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/basics/fun_globals.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ def foo():
1919
foo.__globals__ = None
2020
except AttributeError:
2121
print("AttributeError")
22+
23+
# test closures have the __globals__ attribute
24+
25+
26+
def outer():
27+
x = 1
28+
29+
def inner():
30+
return x
31+
32+
return inner
33+
34+
35+
print(outer.__globals__ is globals())
36+
print(outer().__globals__ is globals())

tests/basics/fun_name.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ def Fun(self):
2424
pass
2525

2626
# name of a function that has closed over variables
27+
# and also the name of the inner closure
2728
def outer():
2829
x = 1
2930
def inner():
3031
return x
3132
return inner
3233
print(outer.__name__)
34+
print(outer().__name__)

0 commit comments

Comments
 (0)
0