[pypy-commit] pypy translation-cleanup: Kill OperationThatShouldNotBePropagatedError
rlamy
noreply at buildbot.pypy.org
Fri Sep 21 19:18:30 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57457:0b4030f9f1d9
Date: 2012-09-21 18:17 +0100
http://bitbucket.org/pypy/pypy/changeset/0b4030f9f1d9/
Log: Kill OperationThatShouldNotBePropagatedError
* Use FlowingError instead
* Improve tests for that case
diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -80,9 +80,6 @@
self.w_type = w_type
self.w_value = w_value
-class OperationThatShouldNotBePropagatedError(FSException):
- pass
-
class ImplicitOperationError(FSException):
pass
@@ -497,11 +494,6 @@
res = getattr(self, methodname)(oparg, next_instr)
if res is not None:
next_instr = res
- except OperationThatShouldNotBePropagatedError, e:
- raise Exception(
- 'found an operation that always raises %s: %s' % (
- self.space.unwrap(e.w_type).__name__,
- self.space.unwrap(e.w_value)))
except FSException, operr:
self.attach_traceback(operr)
next_instr = self.handle_operation_error(operr)
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -8,7 +8,7 @@
from pypy.objspace.flow.model import *
from pypy.objspace.flow import operation
from pypy.objspace.flow.flowcontext import (FlowSpaceFrame, fixeggblocks,
- OperationThatShouldNotBePropagatedError, FSException, FlowingError)
+ FSException, FlowingError)
from pypy.objspace.flow.specialcase import SPECIAL_CASES
from pypy.rlib.unroll import unrolling_iterable, _unroller
from pypy.rlib import rstackovf, rarithmetic
@@ -333,10 +333,9 @@
result = getattr(obj, name)
except Exception, e:
etype = e.__class__
- msg = "generated by a constant operation:\n\t%s%r" % (
- 'getattr', (obj, name))
- raise OperationThatShouldNotBePropagatedError(
- self.wrap(etype), self.wrap(msg))
+ msg = "getattr(%s, %s) always raises %s: %s" % (
+ obj, name, etype, e)
+ raise FlowingError(self.frame, msg)
try:
return self.wrap(result)
except WrapException:
@@ -491,10 +490,9 @@
result = op(*args)
except Exception, e:
etype = e.__class__
- msg = "generated by a constant operation:\n\t%s%r" % (
- name, tuple(args))
- raise OperationThatShouldNotBePropagatedError(
- self.wrap(etype), self.wrap(msg))
+ msg = "%s%r always raises %s: %s" % (
+ name, tuple(args), etype, e)
+ raise FlowingError(self.frame, msg)
else:
# don't try to constant-fold operations giving a 'long'
# result. The result is probably meant to be sent to
diff --git a/pypy/objspace/flow/test/test_objspace.py b/pypy/objspace/flow/test/test_objspace.py
--- a/pypy/objspace/flow/test/test_objspace.py
+++ b/pypy/objspace/flow/test/test_objspace.py
@@ -962,14 +962,23 @@
return s[-3:]
check(f3, 'llo')
- def test_propagate_attribute_error(self):
+ def test_constfold_attribute_error(self):
def f(x):
try:
"".invalid
finally:
if x and 0:
raise TypeError()
- py.test.raises(Exception, self.codetest, f)
+ with py.test.raises(FlowingError) as excinfo:
+ self.codetest(f)
+ assert 'getattr' in str(excinfo.value)
+
+ def test_constfold_exception(self):
+ def f():
+ return (3 + 2)/(4 - 2*2)
+ with py.test.raises(FlowingError) as excinfo:
+ self.codetest(f)
+ assert 'div(5, 0)' in str(excinfo.value)
def test__flowspace_rewrite_directly_as_(self):
def g(x):
More information about the pypy-commit
mailing list