-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[ruff
] re
and regex
calls with unraw string as first argument (RUF039
)
#14446
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF039 | 199 | 199 | 0 | 0 | 0 |
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.
Thanks. This overall looks good. I'm interested in your and @AlexWaygood's opinion on flagging non-raw strings for all regex patterns or if we should make the rule slightly more clever, e.g. by allowing regex patterns containing an escape sequence that can't be written as a raw string (e.g. \n
)
I think this should be a blanket enforcement. # It's too easy to use a normal string as the pattern...
re.compile('uv') # `uv` anywhere (`uv`, `uvicorn`, `dhruv`, `juvenile`, etc.)
# ...then forget to switch to a raw string when the pattern changes.
re.compile('\buv\b') # `uv` not within a word? |
I don't disagree with this overall, but it does mean that it gives you false positives for e.g. |
So maybe that's specific to escape sequences. Python regex support all other common escape sequences (with the exception of |
Oh,
|
I haven't studied this in depth, but it overall seems reasonable to me, both in concept and implementation. I wondered if we needed to take account of this footgun to do with raw strings (they cannot end with an odd number of backslashes). But I think we should be fine, since that documentation states:
|
ruff
] re
and regex
calls with unraw string as first argument (RUF051
)ruff
] re
and regex
calls with unraw string as first argument (RUF039
)
Summary
Resolves #11167.
Test Plan
cargo nextest run
andcargo insta test
.