File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 7
7
import sys
8
8
# testing import *
9
9
from sys import *
10
- import textwrap
11
10
12
11
# different import patterns to check that __annotations__ does not interfere
13
12
# with import machinery
@@ -302,12 +301,6 @@ def one():
302
301
[list ][0 ]: type
303
302
my_lst [one ()- 1 ]: int = 5
304
303
self .assertEqual (my_lst , [5 ])
305
- exec (textwrap .dedent ("""
306
- def f():
307
- global x
308
- x = 1
309
- x:int = 3
310
- """ ))
311
304
312
305
def test_var_annot_syntax_errors (self ):
313
306
# parser pass
Original file line number Diff line number Diff line change @@ -144,6 +144,16 @@ def test_annotated(self):
144
144
self .assertTrue (st4 .lookup ('x' ).is_local ())
145
145
self .assertFalse (st4 .lookup ('x' ).is_annotated ())
146
146
147
+ # Test that annotations in the global scope are valid after the
148
+ # variable is declared as nonlocal.
149
+ st5 = symtable .symtable ('global x\n x: 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
+
147
157
def test_imported (self ):
148
158
self .assertTrue (self .top .lookup ("sys" ).is_imported ())
149
159
You can’t perform that action at this time.
0 commit comments