[issue40546] Inconsistencies between PEG parser and traceback SyntaxErrors
Guido van Rossum
report at bugs.python.org
Thu May 7 15:08:40 EDT 2020
Guido van Rossum <guido at python.org> added the comment:
Aha! So the traceback module does have a difference.
First, if the offset points inside the text, there's no difference:
>>> raise SyntaxError("message", ("<file>", 1, 4, "text"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<file>", line 1
text
^
SyntaxError: message
traceback.print_exception(SyntaxError, SyntaxError("message", ("<file>", 1, 4, "text")), None)
File "<file>", line 1
text
^
SyntaxError: message
>>>
But if the offset points past the text, there's a difference:
>>> raise SyntaxError("message", ("<file>", 1, 5, "text"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<file>", line 1
text
^
SyntaxError: message
>>> traceback.print_exception(SyntaxError, SyntaxError("message", ("<file>", 1, 5, "text")), None)
File "<file>", line 1
text
^
SyntaxError: message
>>>
And even:
>>> raise SyntaxError("message", ("<file>", 1, 10, "text"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<file>", line 1
text
^
SyntaxError: message
>>> traceback.print_exception(SyntaxError, SyntaxError("message", ("<file>", 1, 10, "text")), None)
File "<file>", line 1
text
^
SyntaxError: message
>>>
I wonder if we need to support the final case? It seems clear to me that if the col_offset points just past the text, we should display a caret just past the text. (I wonder if this might be an off-by-one issue caused by confusion about 0-based vs. 1-based offsets.)
But if the col_offset points way past the text, what should happen? The clipping there seems reasonable.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40546>
_______________________________________
More information about the Python-bugs-list
mailing list