Skip to content

Commit 9cb7324

Browse files
sobolevnpablogsal
authored andcommitted
[3.11] gh-96587: Raise SyntaxError for PEP654 on older feature_version (GH-96588) (#96591)
(cherry picked from commit 2c7d2e8) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent 84fd4a5 commit 9cb7324

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Grammar/python.gram

+3-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ try_stmt[stmt_ty]:
412412
| invalid_try_stmt
413413
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
414414
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
415-
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] { _PyAST_TryStar(b, ex, el, f, EXTRA) }
415+
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] {
416+
CHECK_VERSION(stmt_ty, 11, "Exception groups are",
417+
_PyAST_TryStar(b, ex, el, f, EXTRA)) }
416418

417419

418420
# Except statement

Lib/test/test_ast.py

+9
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,15 @@ def test_assignment_expression_feature_version(self):
771771
with self.assertRaises(SyntaxError):
772772
ast.parse('(x := 0)', feature_version=(3, 7))
773773

774+
def test_exception_groups_feature_version(self):
775+
code = dedent('''
776+
try: ...
777+
except* Exception: ...
778+
''')
779+
ast.parse(code)
780+
with self.assertRaises(SyntaxError):
781+
ast.parse(code, feature_version=(3, 10))
782+
774783
def test_constant_as_name(self):
775784
for constant in "True", "False", "None":
776785
expr = ast.Expression(ast.Name(constant, ast.Load()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Correctly raise ``SyntaxError`` on exception groups (:pep:`654`) on python
2+
versions prior to 3.11

Parser/parser.c

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

0 commit comments

Comments
 (0)