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

ast.parse() believes valid context manager py38 syntax to be invalid whenfeature_version=(3, 8) is passed #115881

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@AlexWaygood

Description

@AlexWaygood

Bug report

Bug description:

The following code is completely valid on Python 3.8:

fromcontextlibimportnullcontextwith (nullcontext()ifbool()elsenullcontext()):pass

However, following0daba82 (which was backported to Python 3.11 and Python 3.10),ast.parse() incorrectly throws an error if you try to parse this code withfeature_version=(3, 8):

% python                                                                                                                         Python 3.10.6 (main, Feb 24 2024, 10:35:05) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwinType "help", "copyright", "credits" or "license" for more information.>>>import ast>>> source="""...with (...     nullcontext()ifbool()else nullcontext()... ):...pass...""">>> ast.parse(source,feature_version=(3,8))Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/Users/alexw/.pyenv/versions/3.10.6/lib/python3.10/ast.py", line 50, in parse    return compile(source, filename, mode, flags,  File "<unknown>", line 5    pass        ^SyntaxError: Parenthesized context managers are only supported in Python 3.9 and greater

Cc.@hauntsaninja /@pablogsal

CPython versions tested on:

3.8, 3.9, 3.10, 3.11, 3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp