Skip to content

Commit

Permalink
Fix possible truncated source while colorizing traceback in Python 3.12
Browse files Browse the repository at this point in the history
In particular, a "\" at the end of a line (indicating line
continuation) would have been lost. This is because prior to Python
3.12, the tokenizer would emit "ERRORTOKEN" (as the continuation of the
line is not part of the traceback) but it would be colorized anyway.
With Python 3.12, a "TokenError" is raised instead, which cause the
token iteration to end prematurely. Because of a typo in the code, the
final part of the source (usually empty, except if it couldn't be
tokenized) wasn't added to the output string.
  • Loading branch information
Delgan committed Sep 11, 2023
1 parent db6c40b commit 22bccb7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion loguru/_better_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def highlight(self, source):
_, end_column = end

if start_row != row:
source = source[:column]
source = source[column:]
row, column = start_row, 0

if type_ != tokenize.ENCODING:
Expand Down

0 comments on commit 22bccb7

Please sign in to comment.