Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3.3
Changeset: r70832:a1adffb9acd7
Date: 2014-04-21 21:29 +0200
http://bitbucket.org/pypy/pypy/changeset/a1adffb9acd7/
Log: Convert ast ValidationError to applevel ValueError.
diff --git a/pypy/interpreter/astcompiler/validate.py
b/pypy/interpreter/astcompiler/validate.py
--- a/pypy/interpreter/astcompiler/validate.py
+++ b/pypy/interpreter/astcompiler/validate.py
@@ -11,7 +11,8 @@
class ValidationError(Exception):
- pass
+ def __init__(self, message):
+ self.message = message
def expr_context_name(ctx):
diff --git a/pypy/interpreter/pycompiler.py b/pypy/interpreter/pycompiler.py
--- a/pypy/interpreter/pycompiler.py
+++ b/pypy/interpreter/pycompiler.py
@@ -137,7 +137,11 @@
return code
def validate_ast(self, node):
- validate.validate_ast(self.space, node)
+ try:
+ validate.validate_ast(self.space, node)
+ except validate.ValidationError as e:
+ raise OperationError(self.space.w_ValueError,
+ self.space.wrap(e.message))
def compile_to_ast(self, source, filename, mode, flags):
info = pyparse.CompileInfo(filename, mode, flags)
diff --git a/pypy/interpreter/test/test_compiler.py
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -878,6 +878,15 @@
# the code object's filename comes from the second compilation step
assert co2.co_filename == '%s3' % fname
+ def test_invalid_ast(self):
+ import _ast
+ delete = _ast.Delete([])
+ delete.lineno = 0
+ delete.col_offset = 0
+ mod = _ast.Module([delete])
+ exc = raises(ValueError, compile, mod, 'filename', 'exec')
+ assert str(exc.value) == "empty targets on Delete"
+
class AppTestOptimizer:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit