Title: Tokenize does not roundtrip {{ after \n · Issue #125008 · python/cpython · GitHub
Open Graph Title: Tokenize does not roundtrip {{ after \n · Issue #125008 · python/cpython
X Title: Tokenize does not roundtrip {{ after \n · Issue #125008 · python/cpython
Description: Bug report Bug description: import tokenize, io source_code = r''' f"""{80 * '*'}\n{{test}}{{details}}{{test2}}\n{80 * '*'}""" ''' tokens = tokenize.generate_tokens(io.StringIO(source_code).readline) x = tokenize.untokenize((t,s) for t, ...
Open Graph Description: Bug report Bug description: import tokenize, io source_code = r''' f"""{80 * '*'}\n{{test}}{{details}}{{test2}}\n{80 * '*'}""" ''' tokens = tokenize.generate_tokens(io.StringIO(source_code).readlin...
X Description: Bug report Bug description: import tokenize, io source_code = r''' f"""{80 * '*'}\n{{test}}{{details}}{{test2}}\n{80 * '*'}""" ''...
Opengraph URL: https://github.com/python/cpython/issues/125008
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tokenize does not roundtrip {{ after \\n","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n```python\r\nimport tokenize, io\r\nsource_code = r'''\r\nf\"\"\"{80 * '*'}\\n{{test}}{{details}}{{test2}}\\n{80 * '*'}\"\"\"\r\n'''\r\ntokens = tokenize.generate_tokens(io.StringIO(source_code).readline)\r\nx = tokenize.untokenize((t,s) for t, s, *_ in tokens)\r\nprint(x)\r\n```\r\n\r\nExpected:\r\n```\r\n\r\nf\"\"\"{80 *'*'}\\n{{test}}{{details}}{{test2}}\\n{80 *'*'}\"\"\"\r\n\r\n```\r\n\r\nGot:\r\n```\r\n\r\nf\"\"\"{80 *'*'}\\n{test}}{{details}}{{test2}}\\n{80 *'*'}\"\"\"\r\n\r\n```\r\n\r\nNote the absence of a second { in the {{ after the \\n — but in no other positions.\r\n\r\nUnlike some other roundtrip failures of tokenize, some of which are minor infelicities, this one actually creates a syntactically invalid program on roundtrip, which is quite bad. You get a `SyntaxError: f-string: single '}' is not allowed` when trying to use the results.\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nLinux, Windows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-125013\n* gh-125020\n* gh-125021\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/wyattscarpenter","@type":"Person","name":"wyattscarpenter"},"datePublished":"2024-10-05T17:48:05Z","url":"https://github.com/python/cpython/issues/125008"}
| 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:3db6b3b7-02a2-c574-fbdc-87355730ae93 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9498:2B41BC:CF9EE7:11669F3:6B005231 |
| html-safe-nonce | f32fb74b7a905fd902de2f89743ac131f6b8344c9c78d59ec0a1f1447c11d325 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDk4OjJCNDFCQzpDRjlFRTc6MTE2NjlGMzo2QjAwNTIzMSIsInZpc2l0b3JfaWQiOiIyNTgxNTE1MDAxNTcxMzMyNjU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0a8fe4ff70ae822c82759ec04dd7e4acdfa6686e7e35ddf4fb28d43c7f2aa39b |
| hovercard-subject-tag | issue:2568237292 |
| 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/125008/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3fa05ea88279b527f91f89f8c6f0ecb8e35e3974748b6db3cc0aa9c61dd52c3f/python/cpython/issues/125008 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3fa05ea88279b527f91f89f8c6f0ecb8e35e3974748b6db3cc0aa9c61dd52c3f/python/cpython/issues/125008 |
| og:image:alt | Bug report Bug description: import tokenize, io source_code = r''' f"""{80 * '*'}\n{{test}}{{details}}{{test2}}\n{80 * '*'}""" ''' tokens = tokenize.generate_tokens(io.StringIO(source_code).readlin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wyattscarpenter |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width