Skip to content

Commit 1c7a1c3

Browse files
authored
bpo-46004: Fix error location for loops with invalid targets (GH-29959)
1 parent cf7eaa4 commit 1c7a1c3

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
@@ -227,8 +227,9 @@ _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e)
227227
msg,
228228
_PyPegen_get_expr_name(invalid_target)
229229
);
230+
return RAISE_SYNTAX_ERROR_KNOWN_LOCATION(invalid_target, "invalid syntax");
230231
}
231-
return RAISE_SYNTAX_ERROR("invalid syntax");
232+
return NULL;
232233
}
233234

234235
// Action utility functions

0 commit comments

Comments
 (0)