Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r69085:437833a4447c
Date: 2014-02-06 01:16 +0000
http://bitbucket.org/pypy/pypy/changeset/437833a4447c/
Log: get source information for UnionErrors arising from non-RPython PBCs
(such as ['a', 1])
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -582,18 +582,18 @@
def consider_op(self, block, opindex):
op = block.operations[opindex]
- argcells = [self.binding(a) for a in op.args]
+ try:
+ argcells = [self.binding(a) for a in op.args]
- # let's be careful about avoiding propagated SomeImpossibleValues
- # to enter an op; the latter can result in violations of the
- # more general results invariant: e.g. if SomeImpossibleValue enters
is_
- # is_(SomeImpossibleValue, None) -> SomeBool
- # is_(SomeInstance(not None), None) -> SomeBool(const=False) ...
- # boom -- in the assert of setbinding()
- for arg in argcells:
- if isinstance(arg, annmodel.SomeImpossibleValue):
- raise BlockedInference(self, op, opindex)
- try:
+ # let's be careful about avoiding propagated SomeImpossibleValues
+ # to enter an op; the latter can result in violations of the
+ # more general results invariant: e.g. if SomeImpossibleValue
enters is_
+ # is_(SomeImpossibleValue, None) -> SomeBool
+ # is_(SomeInstance(not None), None) -> SomeBool(const=False) ...
+ # boom -- in the assert of setbinding()
+ for arg in argcells:
+ if isinstance(arg, annmodel.SomeImpossibleValue):
+ raise BlockedInference(self, op, opindex)
resultcell = op.consider(self, *argcells)
except annmodel.AnnotatorError as e: # note that UnionError is a
subclass
graph = self.bookkeeper.position_key[0]
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
@@ -4139,6 +4139,16 @@
a.build_types(f, [str])
assert ("Cannot prove that the object is callable" in exc.value.msg)
+ def test_UnionError_on_PBC(self):
+ l = ['a', 1]
+ def f(x):
+ l.append(x)
+ a = self.RPythonAnnotator()
+ with py.test.raises(annmodel.UnionError) as excinfo:
+ a.build_types(f, [int])
+ assert 'Happened at file' in excinfo.value.source
+ assert 'Known variable annotations:' in excinfo.value.source
+
def test_str_format_error(self):
def f(s, x):
return s.format(x)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit