Title: The lines in tokens from `tokenize.generate_tokens` incorrectly indicate multiple lines. · Issue #104972 · python/cpython · GitHub
Open Graph Title: The lines in tokens from `tokenize.generate_tokens` incorrectly indicate multiple lines. · Issue #104972 · python/cpython
X Title: The lines in tokens from `tokenize.generate_tokens` incorrectly indicate multiple lines. · Issue #104972 · python/cpython
Description: The line attribute in tokens returned by tokenize.generate_tokens incorrectly indicate multiple lines. The tokens should have an invariant that using the .start and .end attributes to index into the .line attribute will produce the .stri...
Open Graph Description: The line attribute in tokens returned by tokenize.generate_tokens incorrectly indicate multiple lines. The tokens should have an invariant that using the .start and .end attributes to index into th...
X Description: The line attribute in tokens returned by tokenize.generate_tokens incorrectly indicate multiple lines. The tokens should have an invariant that using the .start and .end attributes to index into th...
Opengraph URL: https://github.com/python/cpython/issues/104972
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The lines in tokens from `tokenize.generate_tokens` incorrectly indicate multiple lines.","articleBody":"The line attribute in tokens returned by `tokenize.generate_tokens` incorrectly indicate multiple lines. The tokens should have an invariant that using the `.start` and `.end` attributes to index into the `.line` attribute will produce the `.string` attribute.\r\n\r\ntokbug.py:\r\n\r\n```python\r\nimport io\r\nimport sys\r\nimport tokenize\r\n\r\nSOURCE = r\"\"\"\r\na + \\\r\nb\r\n\"\"\"\r\n\r\nprint(sys.version)\r\nreadline = io.StringIO(SOURCE).readline\r\nfor tok in tokenize.generate_tokens(readline):\r\n correct = (tok.string) == (tok.line[tok.start[1]: tok.end[1]])\r\n print(tok, \"\" if correct else \"\u003c*****!!!\")\r\n```\r\n\r\nRun with 3.12.0a7:\r\n```\r\n% /usr/local/pyenv/pyenv/versions/3.12.0a7/bin/python tokbug.py\r\n3.12.0a7 (main, Apr 5 2023, 05:51:58) [Clang 14.0.3 (clang-1403.0.22.14.1)]\r\nTokenInfo(type=62 (NL), string='\\n', start=(1, 0), end=(1, 1), line='\\n')\r\nTokenInfo(type=1 (NAME), string='a', start=(2, 0), end=(2, 1), line='a + \\\\\\n')\r\nTokenInfo(type=54 (OP), string='+', start=(2, 2), end=(2, 3), line='a + \\\\\\n')\r\nTokenInfo(type=1 (NAME), string='b', start=(3, 0), end=(3, 1), line='b\\n')\r\nTokenInfo(type=4 (NEWLINE), string='\\n', start=(3, 1), end=(3, 2), line='b\\n')\r\nTokenInfo(type=0 (ENDMARKER), string='', start=(4, 0), end=(4, 0), line='')\r\n```\r\n\r\nRun with 3.12.0b1:\r\n```\r\n% /usr/local/pyenv/pyenv/versions/3.12.0b1/bin/python tokbug.py\r\n3.12.0b1 (main, May 23 2023, 16:19:59) [Clang 14.0.3 (clang-1403.0.22.14.1)]\r\nTokenInfo(type=65 (NL), string='\\n', start=(1, 0), end=(1, 1), line='\\n')\r\nTokenInfo(type=1 (NAME), string='a', start=(2, 0), end=(2, 1), line='a + \\\\\\n')\r\nTokenInfo(type=55 (OP), string='+', start=(2, 2), end=(2, 3), line='a + \\\\\\n')\r\nTokenInfo(type=1 (NAME), string='b', start=(3, 0), end=(3, 1), line='a + \\\\\\nb\\n') \u003c*****!!!\r\nTokenInfo(type=4 (NEWLINE), string='\\n', start=(3, 1), end=(3, 2), line='a + \\\\\\nb\\n') \u003c*****!!!\r\nTokenInfo(type=0 (ENDMARKER), string='', start=(4, 0), end=(4, 0), line='')\r\n```\r\n\r\nRelated to #104825? cc @pablogsal \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104975\n* gh-104982\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/nedbat","@type":"Person","name":"nedbat"},"datePublished":"2023-05-26T11:47:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/104972/cpython/issues/104972"}
| 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:887098b3-29fa-204f-8739-57f2bfd82e17 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C202:2E599F:5FAC85:82BE4F:6969DC45 |
| html-safe-nonce | 7384cdd5b3ffe3efb4a9a747cd04f7d4fbb4a896334dc1ded4d09b97987468a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjAyOjJFNTk5Rjo1RkFDODU6ODJCRTRGOjY5NjlEQzQ1IiwidmlzaXRvcl9pZCI6IjgyNzY4MDgzNjY2NzExMjU1NzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cb91ea99d5ad2e1b6090d701f94013afa8213fc287104a1689fde092b863f608 |
| hovercard-subject-tag | issue:1727472250 |
| 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/104972/issue_layout |
| twitter:image | https://opengraph.githubassets.com/531eb64c54265ef335154578b990b65caeed3ea2fa028d38032b8a53695c7d82/python/cpython/issues/104972 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/531eb64c54265ef335154578b990b65caeed3ea2fa028d38032b8a53695c7d82/python/cpython/issues/104972 |
| og:image:alt | The line attribute in tokens returned by tokenize.generate_tokens incorrectly indicate multiple lines. The tokens should have an invariant that using the .start and .end attributes to index into th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nedbat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width