Skip to content

Commit a965db3

Browse files
authored
gh-94996: Disallow lambda pos only params with feature_version < (3, 8) (GH-95934)
1 parent b5e3ea2 commit a965db3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Grammar/python.gram

+2-2
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,9 @@ lambda_params[arguments_ty]:
830830
#
831831
lambda_parameters[arguments_ty]:
832832
| a=lambda_slash_no_default b[asdl_arg_seq*]=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] {
833-
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
833+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, a, NULL, b, c, d)) }
834834
| a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] {
835-
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
835+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, NULL, a, NULL, b, c)) }
836836
| a[asdl_arg_seq*]=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] {
837837
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
838838
| a=lambda_param_with_default+ b=[lambda_star_etc] { _PyPegen_make_arguments(p, NULL, NULL, NULL, a, b)}

Lib/test/test_ast.py

+7
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,13 @@ def test_positional_only_feature_version(self):
746746
with self.assertRaises(SyntaxError):
747747
ast.parse('def bar(x=1, /): ...', feature_version=(3, 7))
748748

749+
ast.parse('lambda x, /: ...', feature_version=(3, 8))
750+
ast.parse('lambda x=1, /: ...', feature_version=(3, 8))
751+
with self.assertRaises(SyntaxError):
752+
ast.parse('lambda x, /: ...', feature_version=(3, 7))
753+
with self.assertRaises(SyntaxError):
754+
ast.parse('lambda x=1, /: ...', feature_version=(3, 7))
755+
749756
def test_parenthesized_with_feature_version(self):
750757
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 10))
751758
# While advertised as a feature in Python 3.10, this was allowed starting 3.9

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)