summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-06-24 23:34:15 +1000
committerDamien George <damien@micropython.org>2022-06-24 23:55:13 +1000
commit268ec1e3eb818c92f2ad0015902afef4c4c59ba5 (patch)
tree621e8cfd134b46e0345d758d7f9ef93757b8ec8c /tests
parentd68532558d0f60737ccd5a38ae33f719333520a4 (diff)
tests/basics: Add tests for __name__ and __globals__ attrs on closures.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/fun_globals.py15
-rw-r--r--tests/basics/fun_name.py2
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/basics/fun_globals.py b/tests/basics/fun_globals.py
index 3f32e8bdb..69f8638e8 100644
--- a/tests/basics/fun_globals.py
+++ b/tests/basics/fun_globals.py
@@ -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())
diff --git a/tests/basics/fun_name.py b/tests/basics/fun_name.py
index bb1f14992..b2642280a 100644
--- a/tests/basics/fun_name.py
+++ b/tests/basics/fun_name.py
@@ -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__)