is-literal
What it does
Section titled “What it does”Reports an identity test (is or is not) with a string, bytes or number literal, a list, set, dict or comprehension, or a tuple of constants.
Why it matters
Section titled “Why it matters”is compares object identity, not the value. Whether two equal literals are one object depends on the implementation, so x is "a" can be true in one run and false in another. Python warns about it at compile time.
To fix, write == or !=.
Example
Section titled “Example”x = y = 1x is "a"x is not 1b"" is xx is Nonex is Truex is yx == "a"x is [1](1, None) is xx is (1, y)...Configuration
Section titled “Configuration”python: lint: rules: is-literal: warn # off, warn (default), errorEnabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line is-literal in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| ruff | F632 |
full |