Title: t-strings: AST unparsing does not reproduce original formatting · Issue #133581 · python/cpython · GitHub
Open Graph Title: t-strings: AST unparsing does not reproduce original formatting · Issue #133581 · python/cpython
X Title: t-strings: AST unparsing does not reproduce original formatting · Issue #133581 · python/cpython
Description: Bug report Bug description: The AST unparsing of Interpolation objects does not reproduce formatting within interpolations. This is true both for ast.unparse in Python: >>> ast.unparse(ast.parse('t"{a + b}"')) "t'{a + b}'" And for the C ...
Open Graph Description: Bug report Bug description: The AST unparsing of Interpolation objects does not reproduce formatting within interpolations. This is true both for ast.unparse in Python: >>> ast.unparse(ast.parse('t...
X Description: Bug report Bug description: The AST unparsing of Interpolation objects does not reproduce formatting within interpolations. This is true both for ast.unparse in Python: >>> ast.unparse(ast...
Opengraph URL: https://github.com/python/cpython/issues/133581
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"t-strings: AST unparsing does not reproduce original formatting","articleBody":"# Bug report\n\n### Bug description:\n\nThe AST unparsing of `Interpolation` objects does not reproduce formatting within interpolations.\n\nThis is true both for `ast.unparse` in Python:\n\n```\n\u003e\u003e\u003e ast.unparse(ast.parse('t\"{a + b}\"'))\n\"t'{a + b}'\"\n```\n\nAnd for the C unparse that is used by `from __future__ import annotations`:\n\n```\n\u003e\u003e\u003e ns = {}\n\u003e\u003e\u003e exec(\"\"\"\n... from __future__ import annotations\n... def f(x: t\"{a + b}\"): ...\n... \"\"\", ns)\n\u003e\u003e\u003e ns[\"f\"].__annotations__\n{'x': \"t'{a + b}'\"}\n```\n\nIn general, we can't recover the original source exactly, but in this case we do have the original source available:\n\n```\n\u003e\u003e\u003e ast.parse('t\"{a + b}\"').body[0].value.values[0].str\n'a + b'\n```\n\nLet's use it.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-133635\n* gh-133666\n* gh-133724\n* gh-133731\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2025-05-07T14:40:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/133581/cpython/issues/133581"}
| 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:59e953c0-63d4-8084-ae29-d76c4768d1ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E05A:362E85:218AA4:2D240D:6A53FE97 |
| html-safe-nonce | 558c9d9c47cdbda3beaf2fb0424620a93668b4be5449c015fb2fd7c2e2a93e20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDVBOjM2MkU4NToyMThBQTQ6MkQyNDBEOjZBNTNGRTk3IiwidmlzaXRvcl9pZCI6Ijg0NDA2MTU1MTkxMjgxMjE4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aeb5e903111d9687284fb752c8684e61a975fd3503b31d58117eaa0235e2f46b |
| hovercard-subject-tag | issue:3046210163 |
| 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/133581/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ddc4a08274c271b53572b1eaa4d32c703955c1e9bfa7cfb5f5590ebfb8b28fe3/python/cpython/issues/133581 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ddc4a08274c271b53572b1eaa4d32c703955c1e9bfa7cfb5f5590ebfb8b28fe3/python/cpython/issues/133581 |
| og:image:alt | Bug report Bug description: The AST unparsing of Interpolation objects does not reproduce formatting within interpolations. This is true both for ast.unparse in Python: >>> ast.unparse(ast.parse('t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width