mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-46004: Fix error location for loops with invalid targets (GH-29959)
This commit is contained in:
parent
cf7eaa4617
commit
1c7a1c3be0
3 changed files with 5 additions and 1 deletions
|
@ -234,6 +234,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
check("ages = {'Alice'=22, 'Bob'=23}", 1, 16)
|
check("ages = {'Alice'=22, 'Bob'=23}", 1, 16)
|
||||||
check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19)
|
check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19)
|
||||||
check("[a b c d e f]", 1, 2)
|
check("[a b c d e f]", 1, 2)
|
||||||
|
check("for x yfff:", 1, 7)
|
||||||
|
|
||||||
# Errors thrown by compile.c
|
# Errors thrown by compile.c
|
||||||
check('class foo:return 1', 1, 11)
|
check('class foo:return 1', 1, 11)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix the :exc:`SyntaxError` location for errors involving for loops with
|
||||||
|
invalid targets. Patch by Pablo Galindo
|
|
@ -227,8 +227,9 @@ _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e)
|
||||||
msg,
|
msg,
|
||||||
_PyPegen_get_expr_name(invalid_target)
|
_PyPegen_get_expr_name(invalid_target)
|
||||||
);
|
);
|
||||||
|
return RAISE_SYNTAX_ERROR_KNOWN_LOCATION(invalid_target, "invalid syntax");
|
||||||
}
|
}
|
||||||
return RAISE_SYNTAX_ERROR("invalid syntax");
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action utility functions
|
// Action utility functions
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue