classification
Title: Document that no characters are allowed to proceed \ in explicit line joining
Type: Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jim Fasarakis-Hilliard, docs@python, martin.panter, r.david.murray
Priority: normal Keywords:

Created on 2017-04-03 12:49 by Jim Fasarakis-Hilliard, last changed 2017-04-04 17:44 by Jim Fasarakis-Hilliard. This issue is now closed.

Messages (8)
msg291067 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-04-03 12:49
After looking through the code, the tokenizer only allows a new line character to proceed `\` in explicit line joining [1].

The Devguide section on it [2] actually states many of the limitations of using `\` but not directly that nothing is allowed after it (it does have a remark on comments). 

Would it be a good idea to amend it to state that no characters are allowed after `\`?

[1]: https://github.com/python/cpython/blob/734125938d4653459593ebd28a0aec086efb1f27/Parser/tokenizer.c#L1847
[2]: https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining
msg291068 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-04-03 12:57
Alternatively, stripping all white-space that proceed `\` could be considered if it seems like a good idea.
msg291095 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-04-03 23:25
I think you meant "the language reference" rather than "the devguide".  The sentence about the comment is redundant with the preceding line that says that the thing that results in a join is a physical line that ends with a backslash ("that is not part of..."), which is a definitive statement that no characters may follow it.

So, I don't see any doc bug here, unless we want to delete that redundant statement about the comment because it is confusing.  But I doubt we want to do that, as some people will think that a comment is "the same as there being nothing" (despite the statement about "physical line") which it is not.
msg291096 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-04-03 23:26
I also have no idea what your comment about stripping white space is in reference to ;)
msg291097 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-04-04 02:32
I think he means make something like the following legal, where dots (.) indicate space characters:

a.=.\.
....b

At the moment it is a SyntaxError:

>>> a = \ 
  File "<stdin>", line 1
    a = \ 
         ^
SyntaxError: unexpected character after line continuation character

I don’t think it is worthwhile changing that.
msg291108 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-04-04 07:22
Ah, yes, the Ref. Manual, not the devguide, silly mistake.

It definitely isn't a documentation bug (the documentation doesn't state something wrong) as much as I think it might be a slight omission. I really wasn't aware of how strict the tokenizer is with any characters after `\`.
msg291123 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-04-04 14:25
I don't see any omission, myself.  Keep in mind that the language reference is as much or more of a specification as it is a reference, so we tend to try to use the minimum language that precisely describes the expected behavior. Which is why I suggested that if anything the sentence about trailing comments should be dropped :)  

And I would vote -1 on allowing trailing whitespace.  (More than -1, actually :)  If that's what you meant: you said "proceed \", which doesn't sound like *trailing* whitespace.
msg291128 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-04-04 17:44
Gotcha, thanks for the input, David. I'll leave it to you to decide if the sentence on the trailing comments warrants removal.
History
Date User Action Args
2017-04-04 17:44:01Jim Fasarakis-Hilliardsetstatus: open -> closed
resolution: rejected
messages: + msg291128

stage: resolved
2017-04-04 14:25:53r.david.murraysetmessages: + msg291123
2017-04-04 07:22:44Jim Fasarakis-Hilliardsetmessages: + msg291108
2017-04-04 02:32:59martin.pantersetnosy: + martin.panter
messages: + msg291097
2017-04-03 23:26:03r.david.murraysetmessages: + msg291096
2017-04-03 23:25:10r.david.murraysetnosy: + r.david.murray
messages: + msg291095
2017-04-03 12:57:04Jim Fasarakis-Hilliardsetmessages: + msg291068
2017-04-03 12:49:25Jim Fasarakis-Hilliardcreate