summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect
diff options
context:
space:
mode:
authorblhsing <blhsing@gmail.com>2024-11-05 23:53:54 (GMT)
committerGitHub <noreply@github.com>2024-11-05 23:53:54 (GMT)
commit83ba8c2bba834c0b92de669cac16fcda17485e0e (patch)
treeb845c26576d6cb9b669b35e2122d9bdd4e358f14 /Lib/test/test_inspect
parentfc233f46d3761b4e808be2c44fda0b843179004e (diff)
downloadcpython-83ba8c2bba834c0b92de669cac16fcda17485e0e.zip
cpython-83ba8c2bba834c0b92de669cac16fcda17485e0e.tar.gz
cpython-83ba8c2bba834c0b92de669cac16fcda17485e0e.tar.bz2
gh-70764: inspect.getclosurevars now identifies global variables with LOAD_GLOBAL (#120143)
Diffstat (limited to 'Lib/test/test_inspect')
-rw-r--r--Lib/test/test_inspect/test_inspect.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py
index a4430a8..a92627a 100644
--- a/Lib/test/test_inspect/test_inspect.py
+++ b/Lib/test/test_inspect/test_inspect.py
@@ -1960,6 +1960,19 @@ class TestGetClosureVars(unittest.TestCase):
builtin_vars, unbound_names)
self.assertEqual(inspect.getclosurevars(C().f(_arg)), expected)
+ def test_attribute_same_name_as_global_var(self):
+ class C:
+ _global_ref = object()
+ def f():
+ print(C._global_ref, _global_ref)
+ nonlocal_vars = {"C": C}
+ global_vars = {"_global_ref": _global_ref}
+ builtin_vars = {"print": print}
+ unbound_names = {"_global_ref"}
+ expected = inspect.ClosureVars(nonlocal_vars, global_vars,
+ builtin_vars, unbound_names)
+ self.assertEqual(inspect.getclosurevars(f), expected)
+
def test_nonlocal_vars(self):
# More complex tests of nonlocal resolution
def _nonlocal_vars(f):