[3.12] gh-106922: Fix error location for constructs with spaces and parentheses (GH-108959) (#109147)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-09-08 10:04:28 -07:00 committed by GitHub
parent a1ba0e531c
commit af83d1e821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 3 deletions

View file

@ -608,11 +608,21 @@ def _extract_caret_anchors_from_line_segment(segment):
and not operator_str[operator_offset + 1].isspace()
):
right_anchor += 1
while left_anchor < len(segment) and ((ch := segment[left_anchor]).isspace() or ch in ")#"):
left_anchor += 1
right_anchor += 1
return _Anchors(normalize(left_anchor), normalize(right_anchor))
case ast.Subscript():
subscript_start = normalize(expr.value.end_col_offset)
subscript_end = normalize(expr.slice.end_col_offset + 1)
return _Anchors(subscript_start, subscript_end)
left_anchor = normalize(expr.value.end_col_offset)
right_anchor = normalize(expr.slice.end_col_offset + 1)
while left_anchor < len(segment) and ((ch := segment[left_anchor]).isspace() or ch != "["):
left_anchor += 1
while right_anchor < len(segment) and ((ch := segment[right_anchor]).isspace() or ch != "]"):
right_anchor += 1
if right_anchor < len(segment):
right_anchor += 1
return _Anchors(left_anchor, right_anchor)
return None