-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-55688: Add note about ending backslashes for raw strings #94768
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
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dc3888
Add note about ending backslashes for raw strings
slateny 81d05a1
Be more specific with platform
slateny 9e3d190
Move information on raw string and backslashes from tutorial to FAQ e…
slateny efad634
Use string concatenation over strip; add note on backslashed quotes i…
slateny b8e6594
Reword text and move to faq
slateny 3b0de27
improve wording slightly
hauntsaninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text of the addition is fine. But I am wondering whether such a subtle point should be part of the
introduction.rst
. Perhaps keep only the first line and refer to a location with details?(not sure what would be a better location)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not strictly a part of this file, see https://docs.python.org/3/reference/lexical_analysis.html:
... even a raw string cannot end in an odd number of backslashes ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text you added in this PR will end up here: https://docs.python.org/3/tutorial/introduction.html#strings right?
It is an informal introduction, so I would write something like:
There is one subtle aspect to raw strings: a raw string may not end in an odd
number of
\
characters. For details see String and Bytes literalsBut the text added is correct, so it is mostly a matter of style.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reading this, I realize that my comment above doesn't actually address your original concern on whether this is too subtle of a point for the tutorial introduction - IMO, since the section above does talk about escaping quotes as well as raw strings, I think it's somewhat natural to at least mention the case with them combined.
As for how brief a mention, the current phrasing can definitely be made more brief. I think also that just one of the workarounds can be left in, while the other two examples put elsewhere, along with the wording specific to Windows paths. If the section would introduce the problem of raw strings not ending in an odd number of slashes, I think it should also suggest some sort of solution to it, so I would prefer keeping one example in.
As for moving the rest of the information, I don't think the reference is the most appropriate place, maybe instead in some FAQ entry or a howto page?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An FAQ entry sounds reasonable. Maybe we do something like
There is one subtle aspect to raw strings: a raw string may not end in an odd number of \ characters; see [the FAQ entry] for workarounds
?