Title: tokenize in 3.12 makes copies of each line, 3.11 does not · Issue #119654 · python/cpython · GitHub
Open Graph Title: tokenize in 3.12 makes copies of each line, 3.11 does not · Issue #119654 · python/cpython
X Title: tokenize in 3.12 makes copies of each line, 3.11 does not · Issue #119654 · python/cpython
Description: Bug report Bug description: The tokenize module creates TokenInfo objects with a .line attribute. In Python 3.11, each token on a line used the same string object for .line. In 3.12, each token has a new copy of the same string. This is ...
Open Graph Description: Bug report Bug description: The tokenize module creates TokenInfo objects with a .line attribute. In Python 3.11, each token on a line used the same string object for .line. In 3.12, each token has...
X Description: Bug report Bug description: The tokenize module creates TokenInfo objects with a .line attribute. In Python 3.11, each token on a line used the same string object for .line. In 3.12, each token has...
Opengraph URL: https://github.com/python/cpython/issues/119654
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tokenize in 3.12 makes copies of each line, 3.11 does not","articleBody":"# Bug report\n\n### Bug description:\n\nThe tokenize module creates TokenInfo objects with a `.line` attribute. In Python 3.11, each token on a line used the same string object for `.line`. In 3.12, each token has a new copy of the same string.\n\nThis is part of a memory issue reported against coverage.py: https://github.com/nedbat/coveragepy/issues/1791\n\n```python\n# tok.py\n\nimport io\nimport sys\nimport tokenize\n\nprint(f\"{sys.version = }\")\n\ntext = \"lorem ipsum quia dolor sit amet consectetur adipisci velit\"\nreadline = io.StringIO(text).readline\ntoks = list(tokenize.generate_tokens(readline))\n\nprint(f\"{toks[0].line = }\")\nprint(f\"{(toks[0].line == toks[1].line) = }\")\nprint(f\"{(toks[0].line is toks[1].line) = }\")\n```\n3.11 re-uses string objects:\n```\n% python3.11 /tmp/tok.py\nsys.version = '3.11.9 (main, Apr 8 2024, 14:01:56) [Clang 15.0.0 (clang-1500.3.9.4)]'\ntoks[0].line = 'lorem ipsum quia dolor sit amet consectetur adipisci velit'\n(toks[0].line == toks[1].line) = True\n(toks[0].line is toks[1].line) = True\n```\n3.12 (and above) makes new string objects:\n```\n% python3.12 /tmp/tok.py\nsys.version = '3.12.3 (main, Apr 9 2024, 15:45:14) [Clang 15.0.0 (clang-1500.3.9.4)]'\ntoks[0].line = 'lorem ipsum quia dolor sit amet consectetur adipisci velit'\n(toks[0].line == toks[1].line) = True\n(toks[0].line is toks[1].line) = False\n```\n\n### CPython versions tested on:\n\n3.11, 3.12, 3.13, CPython main branch\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/nedbat","@type":"Person","name":"nedbat"},"datePublished":"2024-05-28T11:49:55Z","url":"https://github.com/python/cpython/issues/119654"}
| 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:1ce2c2f2-e4d0-a21b-645e-76c75bfb0fc9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE5C:2E9831:17DBAE3:1F886ED:6B02095E |
| html-safe-nonce | 7bc0b245e208839e491c8e9dad61daf2be6837f93811073e10d3219800184722 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTVDOjJFOTgzMToxN0RCQUUzOjFGODg2RUQ6NkIwMjA5NUUiLCJ2aXNpdG9yX2lkIjoiODg2MzAyMjU5NDU5MzUyNDA2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c2ddca00f2f4dfdced1d02e2b300910935b34b9e3025110067128e5f89f75a12 |
| hovercard-subject-tag | issue:2320864300 |
| 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/119654/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ca8ea0b0a6319e8ce62aee8d7ccea03df04175eb11a3540ef4eebae5259953f7/python/cpython/issues/119654 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ca8ea0b0a6319e8ce62aee8d7ccea03df04175eb11a3540ef4eebae5259953f7/python/cpython/issues/119654 |
| og:image:alt | Bug report Bug description: The tokenize module creates TokenInfo objects with a .line attribute. In Python 3.11, each token on a line used the same string object for .line. In 3.12, each token has... |
| 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 | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width