diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-09-08 17:04:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 17:04:28 (GMT) |
commit | af83d1e8214efc806488226d206c24462686bd1d (patch) | |
tree | 1fae48677fe79a3059e25f3744dccbaf87b4c50c /Python | |
parent | a1ba0e531cd42189d205b249bc6340a0b1027909 (diff) | |
download | cpython-af83d1e8214efc806488226d206c24462686bd1d.zip cpython-af83d1e8214efc806488226d206c24462686bd1d.tar.gz cpython-af83d1e8214efc806488226d206c24462686bd1d.tar.bz2 |
[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>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/traceback.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index b247954..dc25870 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -615,6 +615,11 @@ extract_anchors_from_expr(const char *segment_str, expr_ty expr, Py_ssize_t *lef ++*right_anchor; } + // Keep going if the current char is not ')' + if (i+1 < right->col_offset && (segment_str[i] == ')')) { + continue; + } + // Set the error characters *primary_error_char = "~"; *secondary_error_char = "^"; @@ -625,6 +630,18 @@ extract_anchors_from_expr(const char *segment_str, expr_ty expr, Py_ssize_t *lef case Subscript_kind: { *left_anchor = expr->v.Subscript.value->end_col_offset; *right_anchor = expr->v.Subscript.slice->end_col_offset + 1; + Py_ssize_t str_len = strlen(segment_str); + + // Move right_anchor and left_anchor forward to the first non-whitespace character that is not ']' and '[' + while (*left_anchor < str_len && (IS_WHITESPACE(segment_str[*left_anchor]) || segment_str[*left_anchor] != '[')) { + ++*left_anchor; + } + while (*right_anchor < str_len && (IS_WHITESPACE(segment_str[*right_anchor]) || segment_str[*right_anchor] != ']')) { + ++*right_anchor; + } + if (*right_anchor < str_len){ + *right_anchor += 1; + } // Set the error characters *primary_error_char = "~"; |