Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4ea500

Browse files
committed
Add CHECK_VERSION for type param lists
1 parent 17c8060 commit f4ea500

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Grammar/python.gram

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ type_alias[stmt_ty]:
640640
# Type parameter declaration
641641
# --------------------------
642642

643-
type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' { t }
643+
type_params[asdl_typeparam_seq*]: '[' t=type_param_seq ']' {
644+
CHECK_VERSION(asdl_typeparam_seq *, 12, "Type parameter lists are", t) }
644645

645646
type_param_seq[asdl_typeparam_seq*]: a[asdl_typeparam_seq*]=','.type_param+ [','] { a }
646647

Lib/test/test_ast.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,18 @@ def test_exception_groups_feature_version(self):
802802
with self.assertRaises(SyntaxError):
803803
ast.parse(code, feature_version=(3, 10))
804804

805+
def test_type_params_feature_version(self):
806+
samples = [
807+
"type X = int",
808+
"class X[T]: pass",
809+
"def f[T](): pass",
810+
]
811+
for sample in samples:
812+
with self.subTest(sample):
813+
ast.parse(sample)
814+
with self.assertRaises(SyntaxError):
815+
ast.parse(sample, feature_version=(3, 11))
816+
805817
def test_invalid_major_feature_version(self):
806818
with self.assertRaises(ValueError):
807819
ast.parse('pass', feature_version=(2, 7))

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)