Author: Armin Rigo <[email protected]>
Branch:
Changeset: r97341:2dceead28db5
Date: 2019-08-30 13:57 +0200
http://bitbucket.org/pypy/pypy/changeset/2dceead28db5/
Log: Don't make an RPython subclass of AssertionError or
NotImplementedError for the purpose of "catching" it: it would work
around the detection logic but not actually work at all
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -566,11 +566,12 @@
if not isinstance(w_check_class, Constant):
raise FlowingError("Non-constant except guard.")
check_class = w_check_class.value
- if check_class in (NotImplementedError, AssertionError):
- raise FlowingError(
- "Catching %s is not valid in RPython" % check_class.__name__)
if not isinstance(check_class, tuple):
# the simple case
+ if issubclass(check_class, (NotImplementedError, AssertionError)):
+ raise FlowingError(
+ "Catching %s is not valid in RPython" %
+ check_class.__name__)
return self.guessbool(op.issubtype(w_exc_type,
w_check_class).eval(self))
# special case for StackOverflow (see rlib/rstackovf.py)
if check_class == rstackovf.StackOverflow:
diff --git a/rpython/flowspace/test/test_objspace.py
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -1135,6 +1135,23 @@
pass
py.test.raises(FlowingError, "self.codetest(f)")
+ def test_cannot_catch_special_exceptions_2(self):
+ class MyNIE(NotImplementedError):
+ pass
+ def f():
+ try:
+ f()
+ except MyNIE:
+ pass
+ py.test.raises(FlowingError, "self.codetest(f)")
+ #
+ def f():
+ try:
+ f()
+ except (ValueError, MyNIE):
+ pass
+ py.test.raises(FlowingError, "self.codetest(f)")
+
def test_locals_dict(self):
def f():
x = 5
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit