Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r91364:1d471fdc1963
Date: 2017-05-22 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/1d471fdc1963/
Log: fix issue #1877: replace bare Exceptions with AnnotatorError in the
annotator
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -514,13 +514,13 @@
ne = eq
def lt((tup1, tup2)):
- raise Exception("unsupported: (...) < (...)")
+ raise AnnotatorError("unsupported: (...) < (...)")
def le((tup1, tup2)):
- raise Exception("unsupported: (...) <= (...)")
+ raise AnnotatorError("unsupported: (...) <= (...)")
def gt((tup1, tup2)):
- raise Exception("unsupported: (...) > (...)")
+ raise AnnotatorError("unsupported: (...) > (...)")
def ge((tup1, tup2)):
- raise Exception("unsupported: (...) >= (...)")
+ raise AnnotatorError("unsupported: (...) >= (...)")
class __extend__(pairtype(SomeDict, SomeDict)):
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -15,7 +15,8 @@
SomeDict, SomeBuiltin, SomePBC, SomeInteger, TLS, SomeUnicodeCodePoint,
s_None, s_ImpossibleValue, SomeBool, SomeTuple, SomeException,
SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked,
- SomeWeakRef, SomeByteArray, SomeConstantType, SomeProperty)
+ SomeWeakRef, SomeByteArray, SomeConstantType, SomeProperty,
+ AnnotatorError)
from rpython.annotator.classdesc import ClassDef, ClassDesc
from rpython.annotator.listdef import ListDef, ListItem
from rpython.annotator.dictdef import DictDef
@@ -343,7 +344,7 @@
elif x is None:
return s_None
else:
- raise Exception("Don't know how to represent %r" % (x,))
+ raise AnnotatorError("Don't know how to represent %r" % (x,))
result.const = x
return result
@@ -363,7 +364,7 @@
result = self.newfuncdesc(pyobj)
elif isinstance(pyobj, (type, types.ClassType)):
if pyobj is object:
- raise Exception("ClassDesc for object not supported")
+ raise AnnotatorError("ClassDesc for object not supported")
if pyobj.__module__ == '__builtin__': # avoid making classdefs
for builtin types
result = self.getfrozen(pyobj)
else:
@@ -400,7 +401,7 @@
msg = "object with a __call__ is not RPython"
else:
msg = "unexpected prebuilt constant"
- raise Exception("%s: %r" % (msg, pyobj))
+ raise AnnotatorError("%s: %r" % (msg, pyobj))
result = self.getfrozen(pyobj)
self.descs[obj_key] = result
return result
@@ -589,7 +590,7 @@
for name, value in dict.iteritems():
if value is func:
return cls, name
- raise Exception("could not match bound-method to attribute name: %r" %
(boundmeth,))
+ raise AnnotatorError("could not match bound-method to attribute name: %r"
% (boundmeth,))
def ishashable(x):
try:
diff --git a/rpython/annotator/classdesc.py b/rpython/annotator/classdesc.py
--- a/rpython/annotator/classdesc.py
+++ b/rpython/annotator/classdesc.py
@@ -550,8 +550,8 @@
"with _mixin_: %r" % (cls,))
base = b1
if mixins_before and mixins_after:
- raise Exception("unsupported: class %r has mixin bases both"
- " before and after the regular base" % (self,))
+ raise AnnotatorError("unsupported: class %r has mixin bases both"
+ " before and after the regular base" %
(self,))
self.add_mixins(mixins_after, check_not_in=base)
self.add_mixins(mixins_before)
self.add_sources_for_class(cls)
@@ -569,8 +569,8 @@
attrs.update(decl)
if self.basedesc is not None:
if self.basedesc.all_enforced_attrs is None:
- raise Exception("%r has slots or _attrs_, "
- "but not its base class" % (cls,))
+ raise AnnotatorError("%r has slots or _attrs_, "
+ "but not its base class" % (cls,))
attrs.update(self.basedesc.all_enforced_attrs)
self.all_enforced_attrs = attrs
@@ -714,8 +714,8 @@
try:
args.fixedunpack(0)
except ValueError:
- raise Exception("default __init__ takes no argument"
- " (class %s)" % (self.name,))
+ raise AnnotatorError("default __init__ takes no argument"
+ " (class %s)" % (self.name,))
elif self.pyobj is Exception:
# check explicitly against "raise Exception, x" where x
# is a low-level exception pointer
@@ -824,8 +824,8 @@
# actual copy in the rtyper). Tested in rpython.rtyper.test.test_rlist,
# test_immutable_list_out_of_instance.
if self._detect_invalid_attrs and attr in self._detect_invalid_attrs:
- raise Exception("field %r was migrated to %r from a subclass in "
- "which it was declared as _immutable_fields_" %
+ raise AnnotatorError("field %r was migrated to %r from a subclass
in "
+ "which it was declared as _immutable_fields_"
%
(attr, self.pyobj))
search1 = '%s[*]' % (attr,)
search2 = '%s?[*]' % (attr,)
@@ -858,7 +858,7 @@
# call to a single class, look at the result annotation
# in case it was specialized
if not isinstance(s_result, SomeInstance):
- raise Exception("calling a class didn't return an instance??")
+ raise AnnotatorError("calling a class didn't return an
instance??")
classdefs = [s_result.classdef]
else:
# call to multiple classes: specialization not supported
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -314,8 +314,8 @@
enforceargs = getattr(self.pyobj, '_annenforceargs_', None)
signature = getattr(self.pyobj, '_signature_', None)
if enforceargs and signature:
- raise Exception("%r: signature and enforceargs cannot both be "
- "used" % (self,))
+ raise AnnotatorError("%r: signature and enforceargs cannot both be
"
+ "used" % (self,))
if enforceargs:
if not callable(enforceargs):
from rpython.annotator.signature import Sig
@@ -432,7 +432,7 @@
def func_args(self, args):
from rpython.annotator.model import SomeInstance
if self.selfclassdef is None:
- raise Exception("calling %r" % (self,))
+ raise AnnotatorError("calling %r" % (self,))
s_instance = SomeInstance(self.selfclassdef, flags=self.flags)
return args.prepend(s_instance)
diff --git a/rpython/annotator/test/test_annrpython.py
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -4584,7 +4584,7 @@
return Ellipsis
a = self.RPythonAnnotator()
e = py.test.raises(Exception, a.build_types, f, [])
- assert str(e.value) == "Don't know how to represent Ellipsis"
+ assert "Don't know how to represent Ellipsis" in str(e.value)
def test_must_be_light_finalizer(self):
from rpython.rlib import rgc
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -185,8 +185,8 @@
return SomeString()
def id(self):
- raise Exception("cannot use id() in RPython; "
- "see objectmodel.compute_xxx()")
+ raise AnnotatorError("cannot use id() in RPython; "
+ "see objectmodel.compute_xxx()")
def int(self):
return SomeInteger()
@@ -421,7 +421,7 @@
def setslice(self, s_start, s_stop, s_iterable):
check_negative_slice(s_start, s_stop)
if not isinstance(s_iterable, SomeList):
- raise Exception("list[start:stop] = x: x must be a list")
+ raise AnnotatorError("list[start:stop] = x: x must be a list")
self.listdef.mutate()
self.listdef.agree(getbookkeeper(), s_iterable.listdef)
self.listdef.resize()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit