-
Notifications
You must be signed in to change notification settings - Fork 2k
FURB156 false positive for multi-character string before in #13802
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingpreviewRelated to preview mode featuresRelated to preview mode features
Description
hardcoded-string-charset (FURB156) has a false positive with an incorrect fix. Given an expression of the form <expression> in <string literal>, the rule tries to replace the string literal with a variable from the string module, ignoring the order of the characters in the string literal. That is only valid when the left-hand-side expression is a string of length 1. If it is multiple characters, reordering the characters in the right-hand-side expression can change the value of the in operation.
$ ruff --version
ruff 0.7.0
$ cat furb156.py
print("89" in "9876543210")
$ python furb156.py
False
$ ruff check --isolated --preview --select FURB156 furb156.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat furb156.py
import string
print("89" in string.digits)
$ python furb156.py
TrueReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpreviewRelated to preview mode featuresRelated to preview mode features