Add tests for global
@@ -27,6 +27,14 @@ def x():
res = x()
assert res == 3, str(res)
+def x():
+ global a
+ global a # a here shouldn't generate SyntaxError
+ a = 3
+
+x()
+assert a == 3
+
# Invalid syntax:
src = """
b = 2
@@ -44,7 +52,6 @@ nonlocal c
with assert_raises(SyntaxError):
exec(src)
-
# Invalid syntax:
src = """
def f():
@@ -62,6 +69,15 @@ def a():
nonlocal a
"""
+with assert_raises(SyntaxError):
+ exec(src)
+
+src = """
+def f():
+ print(a)
+ global a
+"""
+
with assert_raises(SyntaxError):
exec(src)
