Skip to content

Commit 6f50e4a

Browse files
committed
Add tests for global
1 parent 1b141f3 commit 6f50e4a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/snippets/global_nonlocal.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def y():
2727
res = x()
2828
assert res == 3, str(res)
2929

30+
def x():
31+
global a
32+
global a # a here shouldn't generate SyntaxError
33+
a = 3
34+
35+
x()
36+
assert a == 3
37+
3038
# Invalid syntax:
3139
src = """
3240
b = 2
@@ -44,7 +52,6 @@ def y():
4452
with assert_raises(SyntaxError):
4553
exec(src)
4654

47-
4855
# Invalid syntax:
4956
src = """
5057
def f():
@@ -62,6 +69,15 @@ def a():
6269
nonlocal a
6370
"""
6471

72+
with assert_raises(SyntaxError):
73+
exec(src)
74+
75+
src = """
76+
def f():
77+
print(a)
78+
global a
79+
"""
80+
6581
with assert_raises(SyntaxError):
6682
exec(src)
6783

0 commit comments

Comments
 (0)