[ruff] Auto-add r prefix when string has no backslashes for unraw-re-pattern (RUF039)#14536
[ruff] Auto-add r prefix when string has no backslashes for unraw-re-pattern (RUF039)#14536dylwil3 merged 3 commits intoastral-sh:mainfrom
ruff] Auto-add r prefix when string has no backslashes for unraw-re-pattern (RUF039)#14536Conversation
| 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.
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.
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.
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
rprefix. It is used only when the string in question has no backslahses (and also does not have auprefix, since that causes a syntax error.)Closes #14527
Notes: