Skip to content

Commit 0e21eba

Browse files
committed
Move tests to test_symtable.py
1 parent 701bffe commit 0e21eba

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Lib/test/test_grammar.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88
# testing import *
99
from sys import *
10-
import textwrap
1110

1211
# different import patterns to check that __annotations__ does not interfere
1312
# with import machinery
@@ -302,12 +301,6 @@ def one():
302301
[list][0]: type
303302
my_lst[one()-1]: int = 5
304303
self.assertEqual(my_lst, [5])
305-
exec(textwrap.dedent("""
306-
def f():
307-
global x
308-
x = 1
309-
x:int = 3
310-
"""))
311304

312305
def test_var_annot_syntax_errors(self):
313306
# parser pass

Lib/test/test_symtable.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ def test_annotated(self):
144144
self.assertTrue(st4.lookup('x').is_local())
145145
self.assertFalse(st4.lookup('x').is_annotated())
146146

147+
# Test that annotations in the global scope are valid after the
148+
# variable is declared as nonlocal.
149+
st5 = symtable.symtable('global x\nx: int', 'test', 'exec')
150+
self.assertTrue(st5.lookup("x").is_global())
151+
152+
# Test that annotations for nonlocals are valid after the
153+
# variable is declared as nonlocal.
154+
st6 = symtable.symtable('def g():\n x=2\n def f():\n'
155+
' nonlocal x\n x:int', 'test', 'exec')
156+
147157
def test_imported(self):
148158
self.assertTrue(self.top.lookup("sys").is_imported())
149159

0 commit comments

Comments
 (0)