mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
[3.11] gh-99103: Normalize specialized traceback anchors against the current line (#99423)
[3.11] gh-99103: Normalize specialized traceback anchors against the current line (GH-99145)
Automerge-Triggered-By: GH:isidentical.
(cherry picked from commit 57be545959
)
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
parent
2d5f4ba174
commit
a3480ec795
4 changed files with 51 additions and 5 deletions
|
@ -585,12 +585,15 @@ def _extract_caret_anchors_from_line_segment(segment):
|
|||
if len(tree.body) != 1:
|
||||
return None
|
||||
|
||||
normalize = lambda offset: _byte_offset_to_character_offset(segment, offset)
|
||||
statement = tree.body[0]
|
||||
match statement:
|
||||
case ast.Expr(expr):
|
||||
match expr:
|
||||
case ast.BinOp():
|
||||
operator_str = segment[expr.left.end_col_offset:expr.right.col_offset]
|
||||
operator_start = normalize(expr.left.end_col_offset)
|
||||
operator_end = normalize(expr.right.col_offset)
|
||||
operator_str = segment[operator_start:operator_end]
|
||||
operator_offset = len(operator_str) - len(operator_str.lstrip())
|
||||
|
||||
left_anchor = expr.left.end_col_offset + operator_offset
|
||||
|
@ -600,9 +603,11 @@ def _extract_caret_anchors_from_line_segment(segment):
|
|||
and not operator_str[operator_offset + 1].isspace()
|
||||
):
|
||||
right_anchor += 1
|
||||
return _Anchors(left_anchor, right_anchor)
|
||||
return _Anchors(normalize(left_anchor), normalize(right_anchor))
|
||||
case ast.Subscript():
|
||||
return _Anchors(expr.value.end_col_offset, expr.slice.end_col_offset + 1)
|
||||
subscript_start = normalize(expr.value.end_col_offset)
|
||||
subscript_end = normalize(expr.slice.end_col_offset + 1)
|
||||
return _Anchors(subscript_start, subscript_end)
|
||||
|
||||
return None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue