Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokenize.py emits spurious NEWLINE if file ends on a comment without a newline #105435

Closed
aroberge opened this issue Jun 7, 2023 · 2 comments
Closed
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@aroberge
Copy link

aroberge commented Jun 7, 2023

Bug report

This issue, which was reported in https://bugs.python.org/issue35107#msg328884 for much older Python versions in the case where a file ended on a comment, has resurfaced for Python 3.12.

Python 3.12.0b2 (tags/v3.12.0b2:e6c0efa, Jun  6 2023, 15:37:48) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tokenize
>>> import io
>>> tokenize.untokenize(tokenize.generate_tokens(io.StringIO('#').readline))
'#\n'

Note that the problem also arises in the following example:

>>> tokenize.untokenize(tokenize.generate_tokens(io.StringIO('a\n ').readline))
'a\n \n'

Linked PRs

@aroberge aroberge added the type-bug An unexpected behavior, bug, or error label Jun 7, 2023
@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 7, 2023

This looks similar to #105259does the problem still reproduce with 3.12.0b2?

(Cc. @pablogsal / @lysnikolaou)

EDIT: I see you're using 3.12.0b2 already. Apologies.

@pablogsal
Copy link
Member

CC: @mgmacias95

pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 7, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 7, 2023
… without a newline (pythonGH-105442)

(cherry picked from commit 7279fb6)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal pushed a commit that referenced this issue Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants