PEP 657 -- Include Fine Grained Error Locations in Tracebacks

I very, very much like this proposal. However, I would suggest a small change. The PEP currently as written includes the following:

Maintaining the current behavior, only a single line will be displayed in tracebacks. For instructions that span multiple lines (the end offset and the start offset belong to different lines), the end offset will be set to 0 (meaning it is unavailable)

Other enhanced traceback packages [1] often display multiple lines surrounding the actual line where an error was located. Such packages might want to highlight any problem code spanning multiple lines. For such tools, it would be very useful to have the end offset NOT set to zero when it is on a different line. If the end line was recorded, CPython could simply use the fact that the end line was different from the beginning line the same way that “end offset == 0” is currently proposed; other packages could make use of the entire information as needed.

[1] An example of such a package is GitHub - aroberge/friendly: Aimed at Python beginners: replacing standard traceback by something easier to understand. In some cases, friendly already shows similar enhanced information about the location in tracebacks as shown on the picture below. A list of other enhanced traceback packages can be found at the bottom of Some thoughts on the design of friendly — friendly-traceback 0.3.142 documentation

2 Likes