Skip to content

Commit f2220f7

Browse files
committed
Apply suggestions
1 parent f5af20e commit f2220f7

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

Lib/test/test_traceback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3390,7 +3390,7 @@ def func():
33903390

33913391
actual = self.get_suggestion(func)
33923392
self.assertNotIn("blech", actual)
3393-
3393+
33943394
def test_name_error_with_instance(self):
33953395
class A:
33963396
def __init__(self):

Lib/traceback.py

Lines changed: 7 additions & 3 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

@@ -1045,7 +1049,7 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
10451049
self = frame.f_locals['self']
10461050
if hasattr(self, wrong_name):
10471051
return f"self.{wrong_name}"
1048-
1052+
10491053
# Compute closest match
10501054

10511055
if len(d) > _MAX_CANDIDATE_ITEMS:
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
@@ -700,9 +700,11 @@ extract_anchors_from_line(PyObject *filename, PyObject *line,
700700

701701
done:
702702
if (res > 0) {
703-
// Normalize the AST offsets to byte offsets and adjust it with the
703+
// Normalize the AST offsets to byte offsets and adjust them with the
704704
// start of the actual line (instead of the source code segment).
705705
assert(segment != NULL);
706+
assert(*left_anchor >= 0);
707+
assert(*right_anchor >= 0);
706708
*left_anchor = _PyPegen_byte_offset_to_character_offset(segment, *left_anchor) + start_offset;
707709
*right_anchor = _PyPegen_byte_offset_to_character_offset(segment, *right_anchor) + start_offset;
708710
}

0 commit comments

Comments
 (0)