1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
Subject: Fix broken testcase for Python 3.12
Author: Yifei <directoryyf@gmail.com>
Forwarded: not-needed
This patch was applied upstream to fix a testcase with Python 3.12.
---
data/python.gram | 7 ++++---
tests/python_parser/test_syntax_error_handling.py | 4 ++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/data/python.gram b/data/python.gram
index b6853f2..4777ebb 100644
--- a/data/python.gram
+++ b/data/python.gram
@@ -1805,6 +1805,7 @@ kwargs[list]:
starred_expression:
| invalid_starred_expression
| '*' a=expression { ast.Starred(value=a, ctx=Load, LOCATIONS) }
+ | '*' { self.raise_syntax_error("Invalid star expression") }
kwarg_or_starred:
| invalid_kwarg
@@ -1921,10 +1922,10 @@ func_type_comment:
# From here on, there are rules for invalid syntax with specialised error messages
invalid_arguments[NoReturn]:
- | a=args ',' '*' {
- self.raise_syntax_error_known_location(
+ | ((','.(starred_expression | ( assignment_expression | expression !':=') !'=')+ ',' kwargs) | kwargs) a=',' ','.(starred_expression !'=')+ {
+ self.raise_syntax_error_starting_from(
"iterable argument unpacking follows keyword argument unpacking",
- a[1][-1] if a[1] else a[0][-1],
+ a,
)
}
| a=expression b=for_if_clauses ',' [args | expression for_if_clauses] {
diff --git a/tests/python_parser/test_syntax_error_handling.py b/tests/python_parser/test_syntax_error_handling.py
index 712a9a2..cdba57e 100644
--- a/tests/python_parser/test_syntax_error_handling.py
+++ b/tests/python_parser/test_syntax_error_handling.py
@@ -210,8 +210,8 @@ def test_invalid_statements(
(
"f(**a, *b)",
"iterable argument unpacking follows keyword argument unpacking",
- (1, 3),
- (1, 6),
+ (1, 6) if sys.version_info >= (3, 12) else None,
+ (1, 10) if sys.version_info >= (3, 12) else None,
),
# NOTE CPython bug, should report 15 as expected (we use None to omit the check)
("f(a for a in b, c)", "Generator expression must be parenthesized", (1, 3), (1, None)),
|