diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-10-14 18:01:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 18:01:03 +0100 |
commit | de2aea0ff02fa9486365ce9d215bef150fae3a0b (patch) | |
tree | 83406b50dd7d3f85272bba218927d3ea0f005269 /Lib/test/test_symtable.py | |
parent | bd036d3d15fc1310ccc32a43a3296b8c157ac221 (diff) | |
download | cpython-de2aea0ff02fa9486365ce9d215bef150fae3a0b.tar.gz cpython-de2aea0ff02fa9486365ce9d215bef150fae3a0b.zip |
bpo-34939: Allow annotated global names in module namespace (GH-9844)
Allow annotated global names in the module namespace after the symbol is
declared as global. Previously, only symbols annotated before they are declared
as global (i.e. inside a function) were allowed. This change allows symbols to be
declared as global before the annotation happens in the global scope.
Diffstat (limited to 'Lib/test/test_symtable.py')
-rw-r--r-- | Lib/test/test_symtable.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_symtable.py b/Lib/test/test_symtable.py index 2cd735bdc50..8d76f6fe45f 100644 --- a/Lib/test/test_symtable.py +++ b/Lib/test/test_symtable.py @@ -144,6 +144,20 @@ class SymtableTest(unittest.TestCase): self.assertTrue(st4.lookup('x').is_local()) self.assertFalse(st4.lookup('x').is_annotated()) + # Test that annotations in the global scope are valid after the + # variable is declared as nonlocal. + st5 = symtable.symtable('global x\nx: int', 'test', 'exec') + self.assertTrue(st5.lookup("x").is_global()) + + # Test that annotations for nonlocals are valid after the + # variable is declared as nonlocal. + st6 = symtable.symtable('def g():\n' + ' x = 2\n' + ' def f():\n' + ' nonlocal x\n' + ' x: int', + 'test', 'exec') + def test_imported(self): self.assertTrue(self.top.lookup("sys").is_imported()) |