mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
gh-106922: Fix error location for constructs with spaces and parentheses (#108959)
This commit is contained in:
parent
aa51182320
commit
6275c67ea6
4 changed files with 68 additions and 3 deletions
|
@ -616,6 +616,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 = "^";
|
||||
|
@ -626,6 +631,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 = "~";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue