From 22bccb728a83655594a9aba8b2c7e5145d28efe3 Mon Sep 17 00:00:00 2001 From: Delgan Date: Sun, 10 Sep 2023 11:43:33 +0200 Subject: [PATCH] Fix possible truncated source while colorizing traceback in Python 3.12 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. --- loguru/_better_exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loguru/_better_exceptions.py b/loguru/_better_exceptions.py index f815ee89..de44bd54 100644 --- a/loguru/_better_exceptions.py +++ b/loguru/_better_exceptions.py @@ -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: