py/compile: Refine SyntaxError for repeated use of global/nonlocal.

This commit is contained in:
Damien George
2015-09-07 16:55:02 +01:00
parent 3a2171e406
commit 558a016e2c
3 changed files with 35 additions and 8 deletions

View File

@@ -77,8 +77,7 @@ test_syntax("return")
test_syntax("yield")
test_syntax("nonlocal a")
# errors on uPy but shouldn't
#test_syntax("global a; global a")
# error on uPy, warning on CPy
#test_syntax("def f():\n a = 1\n global a")
# default except must be last
@@ -109,3 +108,12 @@ test_syntax("def f(a, a): pass")
# nonlocal must exist in outer function/class scope
test_syntax("def f():\n def g():\n nonlocal a")
# param can't be redefined as global
test_syntax('def f(x):\n global x')
# param can't be redefined as nonlocal
test_syntax('def f(x):\n nonlocal x')
# can define variable to be both nonlocal and global
test_syntax('def f():\n nonlocal x\n global x')