diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-12-07 13:02:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-07 13:02:15 (GMT) |
commit | 1c7a1c3be08ee911d347fffd2716f3911ba751f9 (patch) | |
tree | 1676eca102b29d3abb4fa6162b75e28a5c937a59 | |
parent | cf7eaa4617295747ee5646c4e2b7e7a16d7c64ab (diff) | |
download | cpython-1c7a1c3be08ee911d347fffd2716f3911ba751f9.zip cpython-1c7a1c3be08ee911d347fffd2716f3911ba751f9.tar.gz cpython-1c7a1c3be08ee911d347fffd2716f3911ba751f9.tar.bz2 |
bpo-46004: Fix error location for loops with invalid targets (GH-29959)
-rw-r--r-- | Lib/test/test_exceptions.py | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2021-12-07-11-24-24.bpo-46004.TTEU1p.rst | 2 | ||||
-rw-r--r-- | Parser/pegen.h | 3 |
3 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index e4b7b8f..a954ecb 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -234,6 +234,7 @@ class ExceptionTests(unittest.TestCase): check("ages = {'Alice'=22, 'Bob'=23}", 1, 16) check('match ...:\n case {**rest, "key": value}:\n ...', 2, 19) check("[a b c d e f]", 1, 2) + check("for x yfff:", 1, 7) # Errors thrown by compile.c check('class foo:return 1', 1, 11) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-12-07-11-24-24.bpo-46004.TTEU1p.rst b/Misc/NEWS.d/next/Core and Builtins/2021-12-07-11-24-24.bpo-46004.TTEU1p.rst new file mode 100644 index 0000000..199bccf --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-12-07-11-24-24.bpo-46004.TTEU1p.rst @@ -0,0 +1,2 @@ +Fix the :exc:`SyntaxError` location for errors involving for loops with +invalid targets. Patch by Pablo Galindo diff --git a/Parser/pegen.h b/Parser/pegen.h index 78e75d7..caba34e 100644 --- a/Parser/pegen.h +++ b/Parser/pegen.h @@ -227,8 +227,9 @@ _RAISE_SYNTAX_ERROR_INVALID_TARGET(Parser *p, TARGETS_TYPE type, void *e) msg, _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 |