-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedContributions especially welcomeContributions especially welcome
Description
In Ruff 0.8.1, unnecessary-regular-expression (RUF055) reports a false positive for re.sub when the replacement string contains a backslash.
$ cat ruf055.py
import re
print(re.sub(" ", r"\n", "a b"))
$ python ruf055.py
a
b
$ ruff check --isolated --preview --select RUF055 ruf055.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat ruf055.py
import re
print("a b".replace(" ", "\\n"))
$ python ruf055.py
a\nbThis issue was mentioned in #14679 (comment) with the example of \g<0>, which was deemed acceptably implausible. Because a replacement string can also include character escapes, this issue is plausible.
Alternatively, this could be considered a true positive, in which case the fix needs to interpret escape sequences in the replacement string.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedContributions especially welcomeContributions especially welcome