Skip to content

Commit 6a363e6

Browse files
committed
skip exact tb formatting comparison in python3.13+ and document the divergence
1 parent 859cfef commit 6a363e6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

boltons/tbutils.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ class _DeferredLine:
184184
def __init__(self, filename, lineno, module_globals=None):
185185
self.filename = filename
186186
self.lineno = lineno
187-
# TODO: this is going away when we fix linecache
188-
# TODO: (mark) read about loader
189187
if module_globals is None:
190188
self._mod_name = None
191189
self._mod_loader = None
@@ -660,7 +658,7 @@ def fix_print_exception():
660658
"""
661659
Sets the default exception hook :func:`sys.excepthook` to the
662660
:func:`tbutils.print_exception` that uses all the ``tbutils``
663-
facilities to provide slightly more correct output behavior.
661+
facilities to provide a consistent output behavior.
664662
"""
665663
sys.excepthook = print_exception
666664

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

tests/test_tbutils.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test():
2727
try:
2828
test()
2929
except:
30-
_, _, exc_traceback = sys.exc_info()
30+
exc, _, exc_traceback = sys.exc_info()
3131
tbi = TracebackInfo.from_traceback(exc_traceback)
3232
exc_info = ExceptionInfo.from_exc_info(*sys.exc_info())
3333
exc_info2 = ExceptionInfo.from_current()
@@ -53,7 +53,10 @@ def test():
5353
assert "ValueError('yay fun')" in new_exc_hook_res
5454
assert len(new_exc_hook_res) > len(tbi_str)
5555

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

5861

5962
def test_contextual():

0 commit comments

Comments
 (0)