Skip to content

Commit

Permalink
skip exact tb formatting comparison in python3.13+ and document the d…
Browse files Browse the repository at this point in the history
…ivergence
  • Loading branch information
mahmoud committed Jun 15, 2024
1 parent 2dcff00 commit b4300f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions boltons/tbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ class _DeferredLine:
def __init__(self, filename, lineno, module_globals=None):
self.filename = filename
self.lineno = lineno
# TODO: this is going away when we fix linecache
# TODO: (mark) read about loader
if module_globals is None:
self._mod_name = None
self._mod_loader = None
Expand Down Expand Up @@ -660,7 +658,7 @@ def fix_print_exception():
"""
Sets the default exception hook :func:`sys.excepthook` to the
:func:`tbutils.print_exception` that uses all the ``tbutils``
facilities to provide slightly more correct output behavior.
facilities to provide a consistent output behavior.
"""
sys.excepthook = print_exception

Expand Down Expand Up @@ -715,6 +713,12 @@ def to_string(self):
``ParsedException.from_string(text).to_string()`` should yield
``text``.
.. note::
Note that this method does not output "anchors" (e.g.,
``~~~~~^^``), as were added in Python 3.13. See the built-in
``traceback`` module if these are necessary.
"""
lines = ['Traceback (most recent call last):']

Expand Down
7 changes: 5 additions & 2 deletions tests/test_tbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test():
try:
test()
except:
_, _, exc_traceback = sys.exc_info()
exc, _, exc_traceback = sys.exc_info()
tbi = TracebackInfo.from_traceback(exc_traceback)
exc_info = ExceptionInfo.from_exc_info(*sys.exc_info())
exc_info2 = ExceptionInfo.from_current()
Expand All @@ -53,7 +53,10 @@ def test():
assert "ValueError('yay fun')" in new_exc_hook_res
assert len(new_exc_hook_res) > len(tbi_str)

assert new_exc_hook_res == builtin_exc_hook_res
if sys.version_info <= (3, 12):
# output diverges with Python 3.13+, see https://github.com/mahmoud/boltons/issues/365
# TLDR tbutils only has minimal handling for anchors (e.g., ~~~~^^)
assert new_exc_hook_res == builtin_exc_hook_res


def test_contextual():
Expand Down

0 comments on commit b4300f9

Please sign in to comment.