]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46004: Fix error location for loops with invalid targets (GH-29959)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Tue, 7 Dec 2021 13:02:15 +0000 (13:02 +0000)
committerGitHub <noreply@github.com>
Tue, 7 Dec 2021 13:02:15 +0000 (13:02 +0000)
Lib/test/test_exceptions.py
Misc/NEWS.d/next/Core and Builtins/2021-12-07-11-24-24.bpo-46004.TTEU1p.rst [new file with mode: 0644]
Parser/pegen.h

index e4b7b8f0a6406ff912d18f199c0594fb6dae1e6f..a954ecb8f7c25c8bfdf3441da396ef32d7d24676 100644 (file)
@@ -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 (file)
index 0000000..199bccf
--- /dev/null
@@ -0,0 +1,2 @@
+Fix the :exc:`SyntaxError` location for errors involving for loops with
+invalid targets. Patch by Pablo Galindo
index 78e75d7060cf1d0ce065ae72d6408f0a393a0e68..caba34e535b6aefc1a3f479ab36b2ae0d2772582 100644 (file)
@@ -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