Author: Colin Valliant <alcarithe...@gmail.com> Branch: pep526 Changeset: r93911:2ddcba2e06c4 Date: 2018-02-13 23:21 -0800 http://bitbucket.org/pypy/pypy/changeset/2ddcba2e06c4/
Log: Add WIP test for variable annotation in symtable. diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py b/pypy/interpreter/astcompiler/test/test_symtable.py --- a/pypy/interpreter/astcompiler/test/test_symtable.py +++ b/pypy/interpreter/astcompiler/test/test_symtable.py @@ -486,6 +486,34 @@ scp = self.mod_scope("with x: pass") assert scp.lookup("_[1]") == symtable.SCOPE_LOCAL + def test_annotation_global(self): + src_global = ("def f():\n" + " x: int\n" + " global x\n") + exc_global = py.test.raises(SyntaxError, self.func_scope, src_global).value + assert exc_global.msg == "annotated name 'x' can't be global" + assert exc_global.lineno == 3 + + def test_annotation_nonlocal(self): + src_nonlocal = ("def f():\n" + " x: int\n" + " nonlocal x\n") + exc_nonlocal = py.test.raises(SyntaxError, self.func_scope, src_nonlocal).value + assert exc_nonlocal.msg == "annotated name 'x' can't be nonlocal" + assert exc_nonlocal.lineno == 3 + + def test_annotation_assignment(self): + scp = self.mod_scope("x: int = 1") + assert scp.contains_annotated == True + + scp2 = self.mod_scope("x = 1") + assert scp2.contains_annotated == False + + fscp = self.func_scope("def f(): x: int") + assert fscp.contains_annotated == False + assert fscp.lookup("x") == symtable.SCOPE_LOCAL + + def test_issue13343(self): scp = self.mod_scope("lambda *, k1=x, k2: None") assert scp.lookup("x") == symtable.SCOPE_GLOBAL_IMPLICIT _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit