You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rich tracebacks should display Python 3.11’s fine-grained error locations.
PEP 657 defines codeobject.co_positions() to return an iterable yielding tuples containing (start_line, end_line, start_column, end_column). (note the _column entries are utf-8 byte offsets into the current line, not characters)
It looks like this
try:
1/0exceptException:
_, _, tb=sys.exc_info()
instruction_positions=list(tb.tb_frame.f_code.co_positions())
# seems to be the line & byte offsets of the string “1 / 0” in above code:assertinstruction_positions[tb.tb_lasti] == (2, 2, 4, 9)
But there’s more information in there, e,g, Python 3.11’s whatsnew page displays a zero division error with a pointer distinguishing between the offending operator and the whole expression:
Traceback (most recent call last):
File "calculation.py", line 54, in <module>
result = (x / y / z) * (a / b / c)
~~~~~~^~~ZeroDivisionError: division by zero
There might be inspiration for an implementation found in the many PRs listed in the tracking issue python/cpython#88116
What problem does it solve for you?
Rich should be able to use all information available. Since the release of Python 3.11, the stock traceback formatting might be more useful than rich’s output in some cases (rich displays locals, stock Python displays fine-grained error locations)
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
How would you improve Rich?
Rich tracebacks should display Python 3.11’s fine-grained error locations.
PEP 657 defines
codeobject.co_positions()
to return an iterable yielding tuples containing(start_line, end_line, start_column, end_column)
. (note the_column
entries are utf-8 byte offsets into the current line, not characters)It looks like this
But there’s more information in there, e,g, Python 3.11’s whatsnew page displays a zero division error with a pointer distinguishing between the offending operator and the whole expression:
There might be inspiration for an implementation found in the many PRs listed in the tracking issue python/cpython#88116
What problem does it solve for you?
Rich should be able to use all information available. Since the release of Python 3.11, the stock traceback formatting might be more useful than rich’s output in some cases (rich displays locals, stock Python displays fine-grained error locations)
The text was updated successfully, but these errors were encountered: