[pypy-commit] pypy py3k: special case non BaseException values in excepthook
pjenvey
noreply at buildbot.pypy.org
Sat Feb 23 23:20:49 CET 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61709:ade5d5bcfae9
Date: 2013-02-23 14:17 -0800
http://bitbucket.org/pypy/pypy/changeset/ade5d5bcfae9/
Log: special case non BaseException values in excepthook
diff --git a/pypy/module/sys/app.py b/pypy/module/sys/app.py
--- a/pypy/module/sys/app.py
+++ b/pypy/module/sys/app.py
@@ -8,6 +8,10 @@
def excepthook(exctype, value, traceback):
"""Handle an exception by displaying it with a traceback on sys.stderr."""
+ if not isinstance(value, BaseException):
+ sys.stderr.write("TypeError: print_exception(): Exception expected for "
+ "value, {} found\n".format(type(value).__name__))
+ return
# Flush stdout as well, both files may refer to the same file
try:
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -213,9 +213,14 @@
raise ValueError(42)
except ValueError as exc:
eh(*sys.exc_info())
+ assert err.getvalue().endswith("ValueError: 42\n")
+
+ eh(1, '1', 1)
+ expected = ("TypeError: print_exception(): Exception expected for "
+ "value, str found")
+ assert expected in err.getvalue()
sys.stderr = savestderr
- assert err.getvalue().endswith("ValueError: 42\n")
def test_excepthook_failsafe_path(self):
import traceback
More information about the pypy-commit
mailing list