Skip to content

Commit

Permalink
Merge pull request #1507 from Jaseci-Labs/thakee-bug-traceback
Browse files Browse the repository at this point in the history
runtime error report fails on python 3.12 fix
  • Loading branch information
marsninja authored Jan 6, 2025
2 parents 577af09 + 5267805 commit 3b4bfbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion jac/jaclang/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ def byte_offset_to_char_offset(string: str, offset: int) -> int:
(frame.lineno is not None) and frame.line and frame.line.strip() != ""
):

line_o = frame._original_line.rstrip() # type: ignore [attr-defined]
# Note: This is CPython internals we're trying to get since python doesn't provide
# the frames original line but the stripped version so we had to do this.
line_o = frame.line # Fallback line.
if hasattr(frame, "_original_line"):
line_o = frame._original_line.rstrip() # type: ignore [attr-defined]
elif hasattr(frame, "_original_lines"):
# https://github.com/python/cpython/issues/106922
line_o = frame._original_lines.split("\n")[0].rstrip() # type: ignore [attr-defined]

if frame.colno is not None and frame.end_colno is not None:
off_start = byte_offset_to_char_offset(line_o, frame.colno) - 1
off_end = byte_offset_to_char_offset(line_o, frame.end_colno) - 1
Expand Down

0 comments on commit 3b4bfbc

Please sign in to comment.