-
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
] Auto-add r
prefix when string has no backslashes for unraw-re-pattern (RUF039)
#14536
Conversation
if | ||
// The (no-op) `u` prefix is a syntax error when combined with `r` | ||
!literal.flags.prefix().is_unicode() | ||
&& memchr( |
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.
I don't the we need the performance of memchr here. That's why I would use .contains which is also easier to read
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.
Can you help me get a sense of what size strings the performance starts to make a difference? I only mention it because I have seen some long regexes in my life...
But happy to change it to contains
!
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 less about the length of a string and more that the fix code isn't a hot path.
I don't have too good a sense for when to use memchr otherwise, beyond what the crate documentation mentions
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF039 | 292 | 0 | 20 | 272 | 0 |
W292 | 1 | 1 | 0 | 0 | 0 |
Can you manually run your change on the poetry repo. I suspect that it panics and that this is the reason why we see fewer violations |
Good catch, will do! |
Or is this the same as with TC006 that both poetry and panda set |
Yep it's that, just checked! |
This PR adds a sometimes-available, safe autofix for unraw-re-pattern (RUF039), which prepends an
r
prefix. It is used only when the string in question has no backslahses (and also does not have au
prefix, since that causes a syntax error.)Closes #14527
Notes: