New submission from Andreas Stührk:
The traceback module tries to handle loops caused by an exception's __cause__
or __context__ attributes when printing tracebacks. To do so, it adds already
seen exceptions to a set. Unfortunately, it doesn't handle unhashable
exceptions:
>>> class E(Exception): __hash__ = None
...
>>> traceback.print_exception(E, E(), None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/traceback.py", line 100, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "/usr/lib/python3.5/traceback.py", line 439, in __init__
_seen.add(exc_value)
TypeError: unhashable type: 'E'
CPython's internal exception printing pretty much does the same, except it
ignores any exception while operating on the seen set (see
https://hg.python.org/cpython/file/8ee4ed577c03/Python/pythonrun.c#l813 ff).
Attached is a patch that makes the traceback module ignore TypeErrors while
operating on the seen set. It also adds a (minimal) test.
----------
components: Library (Lib)
files: unhashable_exceptions.diff
keywords: patch
messages: 280022
nosy: Trundle
priority: normal
severity: normal
status: open
title: traceback module can't format/print unhashable exceptions
Added file: http://bugs.python.org/file45342/unhashable_exceptions.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28603>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com