From 268ec1e3eb818c92f2ad0015902afef4c4c59ba5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 24 Jun 2022 23:34:15 +1000 Subject: [PATCH] tests/basics: Add tests for __name__ and __globals__ attrs on closures. Signed-off-by: Damien George --- tests/basics/fun_globals.py | 15 +++++++++++++++ tests/basics/fun_name.py | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tests/basics/fun_globals.py b/tests/basics/fun_globals.py index 3f32e8bdb0..69f8638e8d 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 bb1f14992f..b2642280a2 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__)