Issue 25079: Tokenize generates NL instead of NEWLINE for comments (original) (raw)

Issue25079

Created on 2015-09-12 09:49 by Optimal BPM, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg250516 - (view) Author: Optimal BPM (Optimal BPM) Date: 2015-09-12 09:49
Quoting the documentation: tokenize.NL Token value used to indicate a non-terminating newline. The NEWLINE token indicates the end of a logical line of Python code; NL tokens are generated when a logical line of code is continued over multiple physical lines. This doesn't seem to be entirely true. At the end of comments, an .NL, not .NEWLINE is generated: TokenInfo(type=55 (NL), string='\n', start=(5, 22), end=(5, 23), line='# Some docs for the IF\n') As a comment cannot extend over several lines, if would appear that a NEWLINE would be appropriate?
msg250517 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-12 12:04
See: https://docs.python.org/3/reference/lexical_analysis.html#blank-lines
msg251114 - (view) Author: Optimal BPM (Optimal BPM) Date: 2015-09-19 20:37
OK. But just to make me understand, would that explain why an else statement gets its DEDENT before the else, instead of before an dedented comment just before it? Even if the comment is visually dedented as the else? Example where tokenize returns the DEDENT in a separate place than where it is visually: if a=b: statement # Comment else: other statement In the above case, the DEDENT is reportet before the else, instead of before the comment.
msg251159 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2015-09-20 09:30
As it says in the docs, a "logical line that contains only spaces, tabs, formfeeds and possibly a comment, is ignored." If you write: if a=b: statement # Comment another statement both statements belong to the "if" block. In your example, the comment is similarly part of the "if" block, so the dedent comes after it.
msg251768 - (view) Author: Optimal BPM (Optimal BPM) Date: 2015-09-28 13:45
Ok, I'll work around that then. Thanks for your response!
History
Date User Action Args
2022-04-11 14:58:20 admin set github: 69266
2015-09-28 13:45:20 Optimal BPM set messages: +
2015-09-20 09:30:17 petr.viktorin set nosy: + petr.viktorinmessages: +
2015-09-19 20:37:10 Optimal BPM set messages: +
2015-09-12 12:04:41 skrah set status: open -> closedtype: behavior -> assignee: docs@pythoncomponents: + Documentation, - Interpreter Corenosy: + docs@python, skrahmessages: + resolution: not a bugstage: resolved
2015-09-12 09:49:19 Optimal BPM create