Skip to content

Commit bfa4c6d

Browse files
committed
Apply suggestions
1 parent 224b223 commit bfa4c6d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Lib/traceback.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ def _extract_caret_anchors_from_line_segment(segment):
592592
case ast.Expr(expr):
593593
match expr:
594594
case ast.BinOp():
595-
operator_str = segment[normalize(expr.left.end_col_offset):normalize(expr.right.col_offset)]
595+
operator_start = normalize(expr.left.end_col_offset)
596+
operator_end = normalize(expr.right.col_offset)
597+
operator_str = segment[operator_start:operator_end]
596598
operator_offset = len(operator_str) - len(operator_str.lstrip())
597599

598600
left_anchor = expr.left.end_col_offset + operator_offset
@@ -604,7 +606,9 @@ def _extract_caret_anchors_from_line_segment(segment):
604606
right_anchor += 1
605607
return _Anchors(normalize(left_anchor), normalize(right_anchor))
606608
case ast.Subscript():
607-
return _Anchors(normalize(expr.value.end_col_offset), normalize(expr.slice.end_col_offset + 1))
609+
subscript_start = normalize(expr.value.end_col_offset)
610+
subscript_end = normalize(expr.slice.end_col_offset + 1)
611+
return _Anchors(subscript_start, subscript_end)
608612

609613
return None
610614

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Fix the error reporting positions of specialized traceback anchors when the
2-
source line contains unicode characters.
2+
source line contains Unicode characters.

Python/traceback.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,11 @@ extract_anchors_from_line(PyObject *filename, PyObject *line,
705705

706706
done:
707707
if (res > 0) {
708-
// Normalize the AST offsets to byte offsets and adjust it with the
708+
// Normalize the AST offsets to byte offsets and adjust them with the
709709
// start of the actual line (instead of the source code segment).
710710
assert(segment != NULL);
711+
assert(*left_anchor >= 0);
712+
assert(*right_anchor >= 0);
711713
*left_anchor = _PyPegen_byte_offset_to_character_offset(segment, *left_anchor) + start_offset;
712714
*right_anchor = _PyPegen_byte_offset_to_character_offset(segment, *right_anchor) + start_offset;
713715
}

0 commit comments

Comments
 (0)