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

gh-55688: Add note about ending backslashes for raw strings #94768

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

slateny
Copy link
Contributor

@slateny slateny commented Jul 12, 2022

@bedevere-bot bedevere-bot added awaiting review docs Documentation in the Doc dir labels Jul 12, 2022
@slateny slateny requested a review from bitdancer Oct 13, 2022
Doc/tutorial/introduction.rst Outdated Show resolved Hide resolved
@@ -189,6 +189,29 @@ the first quote::
>>> print(r'C:\some\name') # note the r before the quote
C:\some\name

There is one subtle aspect to raw strings: a raw string may not end in an odd
Copy link
Contributor

@eendebakpt eendebakpt Oct 22, 2022

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)

Copy link
Contributor Author

@slateny slateny Oct 24, 2022

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 ...

Copy link
Contributor

@eendebakpt eendebakpt Oct 24, 2022

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 literals

But the text added is correct, so it is mostly a matter of style.

Copy link
Contributor

@hauntsaninja hauntsaninja left a comment

I agree with eendebakpt that this seems like too subtle a point to spend this much space discussing in the tutorial, so I think we should try to find another home for this.

Maybe a better approach would be to add some special casing to give users a more helpful error message in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants