Skip to content

bpo-30377: Simplify handling of COMMENT and NL in tokenize.py #1607

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

Merged
merged 4 commits into from
May 24, 2017

Conversation

albertjan
Copy link
Contributor

While porting tokenize.py to javascript for skulpt I ran into this bit of code. It check's if a line is a comment more then necessary, this addresses it and makes the code a bit more readable.

Should I also do a PR for this agains 2.7?

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

@mention-bot
Copy link

@albertjan, thanks for your PR! By analyzing the history of the files in this pull request, we identified @tiran, @serhiy-storchaka and @1st1 to be potential reviewers.

@serhiy-storchaka serhiy-storchaka self-requested a review May 16, 2017 16:12
albertjan added 2 commits May 16, 2017 17:21
put both new lines and comments back into one branch and fall though to adding
the newline if it's a comment.
@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label May 16, 2017
@brettcannon
Copy link
Member

Due to a new release of Sphinx, we had to fix the documentation to build on Travis again. Please do a merge to get these changes to help get Travis passing on your PR.

@albertjan
Copy link
Contributor Author

Apparently @the-knights-who-say-ni don't agree with bpo 😄 as bpo now says that I've signed the CLA.

@serhiy-storchaka
Copy link
Member

Finally we convinced him. 😄

@serhiy-storchaka serhiy-storchaka merged commit c471ca4 into python:master May 24, 2017
@albertjan albertjan deleted the fix-issue-30377 branch May 24, 2017 11:34
COMMENT '# NEWLINE' (3, 17) (3, 26)
NEWLINE '\\n' (3, 26) (3, 27)
DEDENT '' (4, 0) (4, 0)
NL '\\n' (3, 4) (3, 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka, this looks invalid to me. Why are there two newlines now? Now the tokenizer claims there's 5 lines in the snippet. There's 4 lines in the snippet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are two lines between the comment an "True". One ends the comment, and other ends the blank line (spaces are ignored).

Look closer on line numbers. "if" is at line 1, the comment is at line 2, "True" is at line 4. Previously the tokenizer reported "True" at line 3.

The fifth line contains only DEDENT. 4 newlines divide the whole text on 5 parts. If you write the sample text in a file and open it with a text editor for sure you could move the cursor on the line 5, just after the 4th newline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was confused by the DEDENT. Thank you for clarification!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused myself too. It looked to me that this change also fixed a bug in line numbering, but I was not able to find a bug in the old code. Later I figured out that the input data for this test was changed, therefore both old and new codes are correct. This PR just cleans up the code, as was claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants