summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorZane Bitter <zbitter@redhat.com>2017-10-17 21:29:39 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-17 21:29:39 (GMT)
commitde86073a761cd3539aaca6f886a1f55effc0d9da (patch)
tree8277693d0d29d8b9cbe06449c9d048fb0aadfe9b /Lib/idlelib
parent191e3138200906e43cba9347177914325b54843f (diff)
downloadcpython-de86073a761cd3539aaca6f886a1f55effc0d9da.zip
cpython-de86073a761cd3539aaca6f886a1f55effc0d9da.tar.gz
cpython-de86073a761cd3539aaca6f886a1f55effc0d9da.tar.bz2
bpo-28603: Fix formatting tracebacks for unhashable exceptions (#4014)
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/idle_test/test_run.py35
-rw-r--r--Lib/idlelib/run.py6
2 files changed, 38 insertions, 3 deletions
diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py
new file mode 100644
index 0000000..d7e627d
--- /dev/null
+++ b/Lib/idlelib/idle_test/test_run.py
@@ -0,0 +1,35 @@
+import unittest
+from unittest import mock
+
+from test.support import captured_stderr
+import idlelib.run as idlerun
+
+
+class RunTest(unittest.TestCase):
+ def test_print_exception_unhashable(self):
+ class UnhashableException(Exception):
+ def __eq__(self, other):
+ return True
+
+ ex1 = UnhashableException('ex1')
+ ex2 = UnhashableException('ex2')
+ try:
+ raise ex2 from ex1
+ except UnhashableException:
+ try:
+ raise ex1
+ except UnhashableException:
+ with captured_stderr() as output:
+ with mock.patch.object(idlerun,
+ 'cleanup_traceback') as ct:
+ ct.side_effect = lambda t, e: t
+ idlerun.print_exception()
+
+ tb = output.getvalue().strip().splitlines()
+ self.assertEqual(11, len(tb))
+ self.assertIn('UnhashableException: ex2', tb[3])
+ self.assertIn('UnhashableException: ex1', tb[10])
+
+
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 39e0c11..6440e67 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -203,16 +203,16 @@ def print_exception():
seen = set()
def print_exc(typ, exc, tb):
- seen.add(exc)
+ seen.add(id(exc))
context = exc.__context__
cause = exc.__cause__
- if cause is not None and cause not in seen:
+ if cause is not None and id(cause) not in seen:
print_exc(type(cause), cause, cause.__traceback__)
print("\nThe above exception was the direct cause "
"of the following exception:\n", file=efile)
elif (context is not None and
not exc.__suppress_context__ and
- context not in seen):
+ id(context) not in seen):
print_exc(type(context), context, context.__traceback__)
print("\nDuring handling of the above exception, "
"another exception occurred:\n", file=efile)