gh-94949: Disallow parsing parenthesised ctx mgr with old feature_ver… · wrongnull/cpython@0daba82 · GitHub
Skip to content

Commit 0daba82

Browse files
pythongh-94949: Disallow parsing parenthesised ctx mgr with old feature_version (python#94950)
* pythongh-94949: Disallow parsing parenthesised ctx manager with old feature_version * 📜🤖 Added by blurb_it. * Allow it with feature_version=(3, 9) as well Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 73eab9f commit 0daba82

4 files changed

Lines changed: 11 additions & 2 deletions

File tree

Grammar/python.gram

Lines changed: 1 addition & 1 deletion

Lib/test/test_ast.py

Lines changed: 8 additions & 0 deletions
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_parenthesized_with_feature_version(self):
742+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 10))
743+
# While advertised as a feature in Python 3.10, this was allowed starting 3.9
744+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 9))
745+
with self.assertRaises(SyntaxError):
746+
ast.parse('with (CtxManager() as example): ...', feature_version=(3, 8))
747+
ast.parse('with CtxManager() as example: ...', feature_version=(3, 8))
748+
741749
def test_issue40614_feature_version(self):
742750
ast.parse('f"{x=}"', feature_version=(3, 8))
743751
with self.assertRaises(SyntaxError):
Lines changed: 1 addition & 0 deletions

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)