diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-09-08 16:18:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 16:18:35 (GMT) |
commit | 6275c67ea68645e5b296a80ea63b90707a0be792 (patch) | |
tree | a2df8ab7f71b96be9a7525015cd05ec16965aa40 /Lib/traceback.py | |
parent | aa51182320f3c391195eb7d5bd970867e63bd978 (diff) | |
download | cpython-6275c67ea68645e5b296a80ea63b90707a0be792.zip cpython-6275c67ea68645e5b296a80ea63b90707a0be792.tar.gz cpython-6275c67ea68645e5b296a80ea63b90707a0be792.tar.bz2 |
gh-106922: Fix error location for constructs with spaces and parentheses (#108959)
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 354754b..67941ff 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -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 |