[pypy-svn] r66251 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test
benjamin at codespeak.net
benjamin at codespeak.net
Wed Jul 15 21:31:23 CEST 2009
Author: benjamin
Date: Wed Jul 15 21:31:23 2009
New Revision: 66251
Modified:
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
Log:
since 'as' is not a keyword we have to check for it
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py Wed Jul 15 21:31:23 2009
@@ -226,6 +226,8 @@
if import_name_type == syms.import_as_name:
name = import_name.children[0].value
if len(import_name.children) == 3:
+ if import_name.children[1].value != "as":
+ self.error("must use 'as' in import", import_name)
as_name = import_name.children[2].value
self.check_forbidden_name(as_name, import_name.children[2])
else:
@@ -236,6 +238,8 @@
if len(import_name.children) == 1:
import_name = import_name.children[0]
continue
+ if import_name.children[1].value != "as":
+ self.error("must use 'as' in import", import_name)
alias = self.alias_for_import_name(import_name.children[0])
asname_node = import_name.children[2]
alias.asname = asname_node.value
Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py (original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py Wed Jul 15 21:31:23 2009
@@ -165,6 +165,8 @@
assert a1.asname is None
assert a2.name == "y"
assert a2.asname == "w"
+ exc = py.test.raises(SyntaxError, self.get_ast, "import x a b").value
+ assert exc.msg == "must use 'as' in import"
def test_from_import(self):
im = self.get_first_stmt("from x import y")
@@ -209,6 +211,9 @@
assert a1.asname == "b"
assert a2.name == "w"
assert a2.asname is None
+ input
+ exc = py.test.raises(SyntaxError, self.get_ast, input).value
+ assert exc.msg == "must use 'as' in import"
input = "from x import a, b,"
exc = py.test.raises(SyntaxError, self.get_ast, input).value
assert exc.msg == "trailing comma is only allowed with surronding " \
More information about the Pypy-commit
mailing list