Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0daba82

Browse files
gh-94949: Disallow parsing parenthesised ctx mgr with old feature_version (#94950)
*gh-94949: Disallow parsing parenthesised ctx manager with old feature_version* 📜🤖 Added by blurb_it.* Allow it with feature_version=(3, 9) as wellCo-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent73eab9f commit0daba82

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

‎Grammar/python.gram‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ for_stmt[stmt_ty]:
391391
with_stmt[stmt_ty]:
392392
| invalid_with_stmt_indent
393393
| 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {
394-
_PyAST_With(a, b, NULL, EXTRA) }
394+
CHECK_VERSION(stmt_ty, 9, "Parenthesized context managers are",_PyAST_With(a, b, NULL, EXTRA)) }
395395
| 'with' a[asdl_withitem_seq*]=','.with_item+ ':' tc=[TYPE_COMMENT] b=block {
396396
_PyAST_With(a, b, NEW_TYPE_COMMENT(p, tc), EXTRA) }
397397
| ASYNC 'with' '(' a[asdl_withitem_seq*]=','.with_item+ ','? ')' ':' b=block {

‎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+
deftest_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+
withself.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
deftest_issue40614_feature_version(self):
742750
ast.parse('f"{x=}"',feature_version=(3,8))
743751
withself.assertRaises(SyntaxError):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:func:`ast.parse` will no longer parse parenthesized context managers when passed ``feature_version`` less than ``(3, 9)``. Patch by Shantanu Jain.

‎Parser/parser.c‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp