Skip to content

Commit d43a358

Browse files
committed
[3.10] bpo-46004: Fix error location for loops with invalid targets (pythonGH-29959).
(cherry picked from commit 1c7a1c3) Co-authored-by: Pablo Galindo Salgado <[email protected]>
1 parent f78c229 commit d43a358

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Lib/test/test_exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def testSyntaxErrorOffset(self):
234234
check("ages = {'Alice'=22, 'Bob'=23}", 1, 16)
235235
check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19)
236236
check("[a b c d e f]", 1, 2)
237+
check("for x yfff:", 1, 7)
237238

238239
# Errors thrown by compile.c
239240
check('class foo:return 1', 1, 11)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the :exc:`SyntaxError` location for errors involving for loops with
2+
invalid targets. Patch by Pablo Galindo

Parser/pegen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e)
321321
msg,
322322
_PyPegen_get_expr_name(invalid_target)
323323
);
324+
return RAISE_SYNTAX_ERROR_KNOWN_LOCATION(invalid_target, "invalid syntax");
324325
}
325-
return RAISE_SYNTAX_ERROR("invalid syntax");
326+
return NULL;
326327
}
327328

328329
void *_PyPegen_arguments_parsing_error(Parser *, expr_ty);

0 commit comments

Comments
 (0)