Title: `ast.parse()` believes valid context manager py38 syntax to be invalid when `feature_version=(3, 8)` is passed · Issue #115881 · python/cpython · GitHub
Open Graph Title: `ast.parse()` believes valid context manager py38 syntax to be invalid when `feature_version=(3, 8)` is passed · Issue #115881 · python/cpython
X Title: `ast.parse()` believes valid context manager py38 syntax to be invalid when `feature_version=(3, 8)` is passed · Issue #115881 · python/cpython
Description: Bug report Bug description: The following code is completely valid on Python 3.8: from contextlib import nullcontext with ( nullcontext() if bool() else nullcontext() ): pass However, following 0daba82 (which was backported to Python 3.1...
Open Graph Description: Bug report Bug description: The following code is completely valid on Python 3.8: from contextlib import nullcontext with ( nullcontext() if bool() else nullcontext() ): pass However, following 0da...
X Description: Bug report Bug description: The following code is completely valid on Python 3.8: from contextlib import nullcontext with ( nullcontext() if bool() else nullcontext() ): pass However, following 0da...
Opengraph URL: https://github.com/python/cpython/issues/115881
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`ast.parse()` believes valid context manager py38 syntax to be invalid when `feature_version=(3, 8)` is passed","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nThe following code is completely valid on Python 3.8:\r\n\r\n```python\r\nfrom contextlib import nullcontext\r\n\r\nwith (\r\n nullcontext() if bool() else nullcontext()\r\n):\r\n pass\r\n```\r\n\r\nHowever, following https://github.com/python/cpython/commit/0daba822212cd5d6c63384a27f390f0945330c2b (which was backported to Python 3.11 and Python 3.10), `ast.parse()` incorrectly throws an error if you try to parse this code with `feature_version=(3, 8)`:\r\n\r\n```pycon\r\n% python \r\nPython 3.10.6 (main, Feb 24 2024, 10:35:05) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>> import ast\r\n>>> source = \"\"\"\r\n... with (\r\n... nullcontext() if bool() else nullcontext()\r\n... ):\r\n... pass\r\n... \"\"\"\r\n>>> ast.parse(source, feature_version=(3, 8))\r\nTraceback (most recent call last):\r\n File \"\u003cstdin>\", line 1, in \u003cmodule>\r\n File \"/Users/alexw/.pyenv/versions/3.10.6/lib/python3.10/ast.py\", line 50, in parse\r\n return compile(source, filename, mode, flags,\r\n File \"\u003cunknown>\", line 5\r\n pass\r\n ^\r\nSyntaxError: Parenthesized context managers are only supported in Python 3.9 and greater\r\n```\r\n\r\nCc. @hauntsaninja / @pablogsal \r\n\r\n### CPython versions tested on:\r\n\r\n3.8, 3.9, 3.10, 3.11, 3.12\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-115920\n* gh-115959\n* gh-115960\n* gh-115980\n* gh-116173\n* gh-116174\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2024-02-24T10:51:54Z","url":"https://github.com/python/cpython/issues/115881"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cdc4912a-0499-061a-7aad-d6afd2c43e1c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B97A:2C3D4F:462A69:5E3A8B:6B002C5B |
| html-safe-nonce | a4b1aecf2b7be7503d98f5b25b7ec59bc21b82068f4de259ce57eccd9f8808b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTdBOjJDM0Q0Rjo0NjJBNjk6NUUzQThCOjZCMDAyQzVCIiwidmlzaXRvcl9pZCI6IjkyMTkyMTA4MDgwNDU2MTIxMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 01ad1b1e1d6275b73379e52964eb434b1996c3e076d3d3c490f8457354190320 |
| hovercard-subject-tag | issue:2152256691 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/115881/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6c40e2f4495e813404a61221ccc5ad34d82e4e17937bf2015771d612959328fe/python/cpython/issues/115881 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6c40e2f4495e813404a61221ccc5ad34d82e4e17937bf2015771d612959328fe/python/cpython/issues/115881 |
| og:image:alt | Bug report Bug description: The following code is completely valid on Python 3.8: from contextlib import nullcontext with ( nullcontext() if bool() else nullcontext() ): pass However, following 0da... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AlexWaygood |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width