Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r66668:43f6c0637201
Date: 2013-08-30 15:45 +0100
http://bitbucket.org/pypy/pypy/changeset/43f6c0637201/
Log: Merged in vext01/pypy/improve-errors-again2 (pull request #186)
Unbreak tests in rlib.
diff --git a/rpython/annotator/listdef.py b/rpython/annotator/listdef.py
--- a/rpython/annotator/listdef.py
+++ b/rpython/annotator/listdef.py
@@ -1,12 +1,12 @@
from rpython.annotator.model import s_ImpossibleValue
from rpython.annotator.model import SomeList, SomeString
-from rpython.annotator.model import unionof, TLS, UnionError
+from rpython.annotator.model import unionof, TLS, UnionError, AnnotatorError
-class TooLateForChange(Exception):
+class TooLateForChange(AnnotatorError):
pass
-class ListChangeUnallowed(Exception):
+class ListChangeUnallowed(AnnotatorError):
pass
class ListItem(object):
diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -5,7 +5,7 @@
from rpython.annotator.model import SomeBool, SomeInteger, SomeString,\
SomeFloat, SomeList, SomeDict, s_None, \
SomeObject, SomeInstance, SomeTuple, lltype_to_annotation,\
- unionof, SomeUnicodeString, SomeType
+ unionof, SomeUnicodeString, SomeType, AnnotatorError
from rpython.annotator.listdef import ListDef
from rpython.annotator.dictdef import DictDef
@@ -118,25 +118,28 @@
else:
args_s.append(annotation(argtype,
bookkeeper=funcdesc.bookkeeper))
if len(inputcells) != len(args_s):
- raise Exception("%r: expected %d args, got %d" % (funcdesc,
+ raise SignatureError("%r: expected %d args, got %d" % (funcdesc,
len(args_s),
len(inputcells)))
for i, (s_arg, s_input) in enumerate(zip(args_s, inputcells)):
s_input = unionof(s_input, s_arg)
if not s_arg.contains(s_input):
- raise Exception("%r argument %d:\n"
+ raise SignatureError("%r argument %d:\n"
"expected %s,\n"
" got %s" % (funcdesc, i+1,
s_arg,
s_input))
inputcells[:] = args_s
+class SignatureError(AnnotatorError):
+ pass
+
def finish_type(paramtype, bookkeeper, func):
from rpython.rlib.types import SelfTypeMarker, AnyTypeMarker
if isinstance(paramtype, SomeObject):
return paramtype
elif isinstance(paramtype, SelfTypeMarker):
- raise Exception("%r argument declared as annotation.types.self();
class needs decorator rlib.signature.finishsigs()" % (func,))
+ raise SignatureError("%r argument declared as annotation.types.self();
class needs decorator rlib.signature.finishsigs()" % (func,))
elif isinstance(paramtype, AnyTypeMarker):
return None
else:
@@ -149,7 +152,7 @@
if s_param is None: # can be anything
continue
if not s_param.contains(s_actual):
- raise Exception("%r argument %d:\n"
+ raise SignatureError("%r argument %d:\n"
"expected %s,\n"
" got %s" % (funcdesc, i+1, s_param, s_actual))
for i, s_param in enumerate(params_s):
@@ -160,7 +163,7 @@
def enforce_signature_return(funcdesc, sigtype, inferredtype):
s_sigret = finish_type(sigtype, funcdesc.bookkeeper, funcdesc.pyobj)
if s_sigret is not None and not s_sigret.contains(inferredtype):
- raise Exception("%r return value:\n"
+ raise SignatureError("%r return value:\n"
"expected %s,\n"
" got %s" % (funcdesc, s_sigret, inferredtype))
return s_sigret
diff --git a/rpython/rlib/test/test_signature.py
b/rpython/rlib/test/test_signature.py
--- a/rpython/rlib/test/test_signature.py
+++ b/rpython/rlib/test/test_signature.py
@@ -2,6 +2,7 @@
from rpython.rlib.signature import signature, finishsigs, FieldSpec, ClassSpec
from rpython.rlib import types
from rpython.annotator import model
+from rpython.annotator.signature import SignatureError
from rpython.translator.translator import TranslationContext, graphof
from rpython.rtyper.lltypesystem import rstr
from rpython.rtyper.annlowlevel import LowLevelAnnotatorPolicy
@@ -24,8 +25,8 @@
return sigof(a, f)
def check_annotator_fails(caller):
- exc = py.test.raises(Exception, annotate_at, caller).value
- assert caller.func_name in repr(exc.args)
+ exc = py.test.raises(model.AnnotatorError, annotate_at, caller).value
+ assert caller.func_name in str(exc)
def test_bookkeeping():
@@ -245,9 +246,9 @@
def incomplete_sig_meth(self):
pass
- exc = py.test.raises(Exception, annotate_at, C.incomplete_sig_meth).value
- assert 'incomplete_sig_meth' in repr(exc.args)
- assert 'finishsigs' in repr(exc.args)
+ exc = py.test.raises(SignatureError, annotate_at,
C.incomplete_sig_meth).value
+ assert 'incomplete_sig_meth' in str(exc)
+ assert 'finishsigs' in str(exc)
def test_any_as_argument():
@signature(types.any(), types.int(), returns=types.float())
@@ -268,8 +269,8 @@
@signature(types.str(), returns=types.int())
def cannot_add_string(x):
return f(x, 2)
- exc = py.test.raises(Exception, annotate_at, cannot_add_string).value
- assert 'Blocked block' in repr(exc.args)
+ exc = py.test.raises(model.AnnotatorError, annotate_at,
cannot_add_string).value
+ assert 'Blocked block' in str(exc)
def test_return_any():
@signature(types.int(), returns=types.any())
@@ -281,9 +282,9 @@
@signature(types.str(), returns=types.any())
def cannot_add_string(x):
return f(3) + x
- exc = py.test.raises(Exception, annotate_at, cannot_add_string).value
- assert 'Blocked block' in repr(exc.args)
- assert 'cannot_add_string' in repr(exc.args)
+ exc = py.test.raises(model.AnnotatorError, annotate_at,
cannot_add_string).value
+ assert 'Blocked block' in str(exc)
+ assert 'cannot_add_string' in str(exc)
diff --git a/rpython/tool/test/test_error.py b/rpython/tool/test/test_error.py
--- a/rpython/tool/test/test_error.py
+++ b/rpython/tool/test/test_error.py
@@ -7,6 +7,13 @@
import py
+def compile_function(function, annotation=[]):
+ t = TranslationContext()
+ t.buildannotator().build_types(function, annotation)
+
+class AAA(object):
+ pass
+
def test_someobject():
def someobject_degeneration(n):
if n == 3:
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit