Skip to content

Commit 9fbc817

Browse files
authoredAug 12, 2022
[3.10] gh-94996: Disallow lambda pos only params with feature_version < (3, 8) (GH-95934) (GH-95938)
(cherry picked from commit a965db3) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Automerge-Triggered-By: GH:lysnikolaou
1 parent a92c2d6 commit 9fbc817

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
@@ -552,9 +552,9 @@ lambda_params[arguments_ty]:
552552
#
553553
lambda_parameters[arguments_ty]:
554554
| a=lambda_slash_no_default b[asdl_arg_seq*]=lambda_param_no_default* c=lambda_param_with_default* d=[lambda_star_etc] {
555-
_PyPegen_make_arguments(p, a, NULL, b, c, d) }
555+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, a, NULL, b, c, d)) }
556556
| a=lambda_slash_with_default b=lambda_param_with_default* c=[lambda_star_etc] {
557-
_PyPegen_make_arguments(p, NULL, a, NULL, b, c) }
557+
CHECK_VERSION(arguments_ty, 8, "Positional-only parameters are", _PyPegen_make_arguments(p, NULL, a, NULL, b, c)) }
558558
| a[asdl_arg_seq*]=lambda_param_no_default+ b=lambda_param_with_default* c=[lambda_star_etc] {
559559
_PyPegen_make_arguments(p, NULL, NULL, a, b, c) }
560560
| 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
@@ -694,6 +694,13 @@ def test_positional_only_feature_version(self):
694694
with self.assertRaises(SyntaxError):
695695
ast.parse('def bar(x=1, /): ...', feature_version=(3, 7))
696696

697+
ast.parse('lambda x, /: ...', feature_version=(3, 8))
698+
ast.parse('lambda x=1, /: ...', feature_version=(3, 8))
699+
with self.assertRaises(SyntaxError):
700+
ast.parse('lambda x, /: ...', feature_version=(3, 7))
701+
with self.assertRaises(SyntaxError):
702+
ast.parse('lambda x=1, /: ...', feature_version=(3, 7))
703+
697704
def test_parenthesized_with_feature_version(self):
698705
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 10))
699706
# While advertised as a feature in Python 3.10, this was allowed starting 3.9

‎Parser/parser.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -11194,7 +11194,7 @@ lambda_parameters_rule(Parser *p)
1119411194
)
1119511195
{
1119611196
D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_no_default lambda_param_no_default* lambda_param_with_default* lambda_star_etc?"));
11197-
_res = _PyPegen_make_arguments ( p , a , NULL , b , c , d );
11197+
_res = CHECK_VERSION ( arguments_ty , 8 , "Positional-only parameters are" , _PyPegen_make_arguments ( p , a , NULL , b , c , d ) );
1119811198
if (_res == NULL && PyErr_Occurred()) {
1119911199
p->error_indicator = 1;
1120011200
p->level--;
@@ -11224,7 +11224,7 @@ lambda_parameters_rule(Parser *p)
1122411224
)
1122511225
{
1122611226
D(fprintf(stderr, "%*c+ lambda_parameters[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "lambda_slash_with_default lambda_param_with_default* lambda_star_etc?"));
11227-
_res = _PyPegen_make_arguments ( p , NULL , a , NULL , b , c );
11227+
_res = CHECK_VERSION ( arguments_ty , 8 , "Positional-only parameters are" , _PyPegen_make_arguments ( p , NULL , a , NULL , b , c ) );
1122811228
if (_res == NULL && PyErr_Occurred()) {
1122911229
p->error_indicator = 1;
1123011230
p->level--;

0 commit comments

Comments
 (0)
Please sign in to comment.