pylint
pylint copied to clipboard
Add clarification of the r string modifier
Raw sting literals may not be easily understood based on the brief description. This description is much more verbose (maybe too verbose) but should help the novice python programmer understand what the r modifier is and how / when to use it.
Type of Changes
| Type | |
|---|---|
| ✓ | :scroll: Docs |
Description
Added a more verbose description of the r (raw string literal) modifier for the novices like me…
I like the idea, but have some suggestions how to improve it:
- There is a bit of inconsistent spelling, sometimes it's "Python", sometimes "python" instead.
- I understand the issue, but if I didn't I wouldn't understand the reference to regular expressions. Make that three paragraphs, one for how escape sequences in strings work, one that explains how to use either raw strings or double backslashes and the third explaining why this is particularly useful for regular expressions.
- "and not to modify it" -> "and not to interpret backslashes as escape characters" (Python strings are immutable already)
Hi @Pierre-Sassoulas. Thanks for the feedback. I am brand new to this project so not sure how to add the link to related.rst. If you can provide an example, I'll give this another try.
My intention with this PR is to try and clarify, or encourage, the use of the r string modifier because, I believe, it probably should be used in the majority of cases.
How about this: Use raw string literals (prefix with 'r') or double backslashes (\\) in Python to avoid escape sequence issues in regex. Example: r"\." or "\\." for a literal dot character.
To me it's only barely better.
@UlrichEckhardt Excellent feedback. Thank you. Let's see if we can get the initial sentence right and then add details to related.rst
Looking forward to your replies.
I agree that this is a bit too verbose for our documentation. We're not trying to explain all of Python, there are excellent resources for that on the internet.
not sure how to add the link to related.rst.
Hey, you can create a file called "doc/data/messages/a/anomalous-backslash-in-string/related.rst", look at other related.rst in the repo for examples :)