Title: Tokenizer produces different output on Windows on py312 for ends of files · Issue #105017 · python/cpython · GitHub
Open Graph Title: Tokenizer produces different output on Windows on py312 for ends of files · Issue #105017 · python/cpython
X Title: Tokenizer produces different output on Windows on py312 for ends of files · Issue #105017 · python/cpython
Description: Bug report If you copy and paste the following code into a repro.py file and run python -m tokenize on it on a Windows machine, the output is different on 3.12/3.13 compared to what it was on 3.11 (the file ends with a single newline): f...
Open Graph Description: Bug report If you copy and paste the following code into a repro.py file and run python -m tokenize on it on a Windows machine, the output is different on 3.12/3.13 compared to what it was on 3.11 ...
X Description: Bug report If you copy and paste the following code into a repro.py file and run python -m tokenize on it on a Windows machine, the output is different on 3.12/3.13 compared to what it was on 3.11 ...
Opengraph URL: https://github.com/python/cpython/issues/105017
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tokenizer produces different output on Windows on py312 for ends of files","articleBody":"# Bug report\r\n\r\nIf you copy and paste the following code into a `repro.py` file and run `python -m tokenize` on it on a Windows machine, the output is different on 3.12/3.13 compared to what it was on 3.11 (the file ends with a single newline):\r\n\r\n```py\r\nfoo = 'bar'\r\nspam = 'eggs'\r\n```\r\n\r\nOn Python 3.11, on Windows, the output is this:\r\n\r\n```\r\n\u003e python -m tokenize cpython/repro.py\r\n0,0-0,0: ENCODING 'utf-8'\r\n1,0-1,3: NAME 'foo'\r\n1,4-1,5: OP '='\r\n1,6-1,11: STRING \"'bar'\"\r\n1,11-1,13: NEWLINE '\\r\\n'\r\n2,0-2,4: NAME 'spam'\r\n2,5-2,6: OP '='\r\n2,7-2,13: STRING \"'eggs'\"\r\n2,13-2,15: NEWLINE '\\r\\n'\r\n3,0-3,0: ENDMARKER ''\r\n```\r\n\r\nOn Python 3.13 (@ https://github.com/python/cpython/commit/6e62eb2e70a9f2a8099735989a58e8c8cfb4a2f2) on Windows, however, the output is this:\r\n\r\n```\r\n\u003e python -m tokenize repro.py\r\n0,0-0,0: ENCODING 'utf-8'\r\n1,0-1,3: NAME 'foo'\r\n1,4-1,5: OP '='\r\n1,6-1,11: STRING \"'bar'\"\r\n1,11-1,12: NEWLINE '\\n'\r\n2,0-2,4: NAME 'spam'\r\n2,5-2,6: OP '='\r\n2,7-2,13: STRING \"'eggs'\"\r\n2,13-2,14: NEWLINE '\\n'\r\n3,0-3,1: NL '\\n'\r\n4,0-4,0: ENDMARKER ''\r\n```\r\n\r\nThere appear to be two changes here:\r\n- All the NEWLINE tokens now have `\\n` values, whereas on Python 3.11 they all had `\\r\\n` values\r\n- There is an additional NL token at the end, immediately before the ENDMARKER token.\r\n\r\nAs discussed in https://github.com/PyCQA/pycodestyle/issues/1142, this appears to be Windows-specific, and _may_ be the cause of a large number of spurious W391 errors from the pycodestyle linting tool. (W391 dictates that there should be one, and only one, newline at the end of a file.) The pycodestyle tool is included in flake8, meaning that test failures in pycodestyle can cause test failures for other flake8 plugins. (All tests for [the flake8-pyi plugin](https://github.com/PyCQA/flake8-pyi), for example, currently fail on Python 3.13 on Windows.)\r\n\r\n# Your environment\r\n\r\n```\r\nPython 3.13.0a0 (heads/main:6e62eb2e70, May 27 2023, 14:00:13) [MSC v.1932 64 bit (AMD64)] on win32\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-105022\n* gh-105023\n* gh-105030\n* gh-105041\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/AlexWaygood","@type":"Person","name":"AlexWaygood"},"datePublished":"2023-05-27T13:14:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/105017/cpython/issues/105017"}
| 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:a8ad056e-177f-e97b-ba53-cb2f0a9db957 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7B4:14EE64:9CF204:D23914:6969BF62 |
| html-safe-nonce | 0c727c8eabd70f89c5c617988a5794b5f072a4f08849ccd9098709beec26a89e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0I0OjE0RUU2NDo5Q0YyMDQ6RDIzOTE0OjY5NjlCRjYyIiwidmlzaXRvcl9pZCI6IjIxMzE4MjY4MDYwNTI0NzA2MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c1ca5d3d8a2d59592d26e93dd05bd711ae3d671bba6c6c585fd82680b700b84a |
| hovercard-subject-tag | issue:1728720333 |
| 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/105017/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8a3958732b5489abdb652bbb6c2ab0029ac1561b3a8f6618af2f241921bd3f40/python/cpython/issues/105017 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8a3958732b5489abdb652bbb6c2ab0029ac1561b3a8f6618af2f241921bd3f40/python/cpython/issues/105017 |
| og:image:alt | Bug report If you copy and paste the following code into a repro.py file and run python -m tokenize on it on a Windows machine, the output is different on 3.12/3.13 compared to what it was on 3.11 ... |
| 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 | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width