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

Skip RUF039 when \n, \t, ... are involved #14529

Closed
alexprengere opened this issue Nov 22, 2024 · 2 comments
Closed

Skip RUF039 when \n, \t, ... are involved #14529

alexprengere opened this issue Nov 22, 2024 · 2 comments
Labels
question Asking for support or clarification

Comments

@alexprengere
Copy link

The latest Ruff 039 rule is a bit noisy (see #14527 too), and I think there are false positives: running it on a private codebase, I had a lot of:

_RE_STRIP = re.compile("[ \t\r\n]+")
                        ^^^^^^^^^^ RUF039
= help: Replace with raw string

Unless I missed something, there is no easy way to convert that one to a raw string, as r"\n" is semantically different to "\n" (but I agree that is a good general rule, when possible).

@MichaReiser MichaReiser added the question Asking for support or clarification label Nov 22, 2024
@MichaReiser
Copy link
Member

Converting to a raw string should be possible for all escape sequence except \b

image
source

You can also verify this using the repl

>>> re.match("\n", "\n")
<re.Match object; span=(0, 1), match='\n'>
>>> re.match(r"\n", "\n")
<re.Match object; span=(0, 1), match='\n'>
>>> 

@alexprengere
Copy link
Author

Thanks for the reply! I guess CPython implemented this to make people's life easier with the raw strings.
It feels a bit weird as it blurs some lines between what is escaped by re and what is escaped when building a string, but I guess as this works, I will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

2 participants