Skip to content

Commit 0755dda

Browse files
committed
pythongh-94996: Disallow parsing pos only param with feature_version < (3, 8)
1 parent 3f2dd0a commit 0755dda

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Grammar/python.gram

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ params[arguments_ty]:
287287

288288
parameters[arguments_ty]:
289289
| a=slash_no_default b[asdl_arg_seq*]=param_no_default* c=param_with_default* d=[star_etc] {
290-
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
290+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, a, NULL, b, c, d)) }
291291
| a=slash_with_default b=param_with_default* c=[star_etc] {
292-
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
292+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, NULL, a, NULL, b, c)) }
293293
| a[asdl_arg_seq*]=param_no_default+ b=param_with_default* c=[star_etc] {
294294
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
295295
| a=param_with_default+ b=[star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}

Lib/test/test_ast.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ def test_ast_asdl_signature(self):
738738
expressions[0] = f"expr = {ast.expr.__subclasses__()[0].__doc__}"
739739
self.assertCountEqual(ast.expr.__doc__.split("\n"), expressions)
740740

741+
def test_positional_only_feature_version(self):
742+
ast.parse('def foo(x, /): ...', feature_version=(3, 8))
743+
ast.parse('def bar(x=1, /): ...', feature_version=(3, 8))
744+
with self.assertRaises(SyntaxError):
745+
ast.parse('def foo(x, /): ...', feature_version=(3, 7))
746+
with self.assertRaises(SyntaxError):
747+
ast.parse('def bar(x=1, /): ...', feature_version=(3, 7))
748+
741749
def test_parenthesized_with_feature_version(self):
742750
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 10))
743751
# While advertised as a feature in Python 3.10, this was allowed starting 3.9
@@ -746,7 +754,7 @@ def test_parenthesized_with_feature_version(self):
746754
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 8))
747755
ast.parse('with CtxManager() as example: ...', feature_version=(3, 8))
748756

749-
def test_issue40614_feature_version(self):
757+
def test_debug_f_string_feature_version(self):
750758
ast.parse('f"{x=}"', feature_version=(3, 8))
751759
with self.assertRaises(SyntaxError):
752760
ast.parse('f"{x=}"', feature_version=(3, 7))

Parser/parser.c

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)