classification
Title: Include column offsets for bytecode instructions
Type: Stage:
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, Mark.Shannon, brandtbucher, nedbat, pablogsal, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2021-04-27 10:58 by pablogsal, last changed 2021-05-05 14:13 by BTaskaya.

Messages (9)
msg392054 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-27 10:58
If we could include column offsets from the AST nodes for every bytecode instructions we could leverage these to offer much better tracebacks and a lot more information to debuggers and similar tools. For instance, in an expression such as:

z['aaaaaa']['bbbbbb']['cccccc']['dddddd].sddfsdf.sdfsdf

where one of these elements is None, we could tell exactly what of these pieces is the actual None and we could do some cool highlighting on tracebacks.

Similarly, coverage tools and debuggers could also make this distinction and therefore could offer reports with more granularity.

The cost is not 0: it would be two integers per bytecode instruction, but I think it may be worth the effort.
msg392062 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-27 12:33
I'm going to prepare a PEP since the discussion regarding if the two integers per bytecode are worth enough is going to be eternal.
msg392081 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-04-27 14:40
The additional cost will not only be the line number table, but we need to store the line for exceptions that are reraised after cleanup.
Adding a column will mean more stack consumption.
msg392082 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-27 14:44
Yup, but I still think is worth the cost, giving that debugging improvements are usually extremely popular among users.
msg392520 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-04-30 22:28
Specific examples of current messages and proposed improvements would help focus discussion.

If you are willing to only handle code lines up to 256 chars, only 2 bytes should be needed.  (0,0) or (255,255) could mean 'somewhere beyond the 256th char'.
msg392540 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-30 23:25
> Specific examples of current messages and proposed improvements would help focus discussion.


Yeah, I am proposing going from:

>>> x['aaaaaa']['bbbbbb']['cccccc']['dddddd'].sddfsdf.sdfsdf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable

to

>>> x['aaaaaa']['bbbbbb']['cccccc']['dddddd'].sddfsdf.sdfsdf
                         ^^^^^^^^^^
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable
msg392541 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-30 23:26
Basically, to highlight in all exceptions the range in the displayed line where the error ocurred. For instance:


>>> foo(a, b/z+2, c, 132432 /x, d /y)
                     ^^^^^^^^^
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
msg392555 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-05-01 00:51
Marking what expression evaluated to None would be extremely helpful.  So would marking the 0 denominator when there is more than one candidate: "e = a/b + c/d".  It should be easy to revise IDLE Shell's print_exception to tag the span.  In some cases, the code that goes from a traceback line to a line in a file and marks it could do the same.

What would you do when the expression is not the last line?

try:
    x/y
    ...
except Exception as e:
   ...
   raise e

The except and raise might even be in a separate module.
I look forward to the PEP and discussion.
msg392557 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-01 00:59
> So would marking the 0 denominator when there is more than one candidate: "e = a/b + c/d".

No, it will mark the offset of the bytecode that was getting executed when the exception was raised. Is just a way to mark what is raising the particular exception

> What would you do when the expression is not the last line?

There is some logic needed to re-raise exceptions. But basically it boils down to comparate the line numbers to decide if you want to propagate or not the offsets.
History
Date User Action Args
2021-05-05 14:13:53BTaskayasetnosy: + BTaskaya
2021-05-01 00:59:23pablogsalsetmessages: + msg392557
2021-05-01 00:51:48terry.reedysetmessages: + msg392555
2021-04-30 23:51:16brandtbuchersetnosy: + brandtbucher
2021-04-30 23:26:53pablogsalsetmessages: + msg392541
2021-04-30 23:25:22pablogsalsetmessages: + msg392540
2021-04-30 22:28:13terry.reedysetnosy: + terry.reedy
messages: + msg392520
2021-04-27 14:44:12pablogsalsetmessages: + msg392082
2021-04-27 14:40:46Mark.Shannonsetmessages: + msg392081
2021-04-27 12:33:31pablogsalsetmessages: + msg392062
2021-04-27 10:58:54pablogsalsetnosy: + nedbat, serhiy.storchaka
2021-04-27 10:58:38pablogsalcreate