Guido van Rossum <gu...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue40546>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to