Skip to content

is-literal

Pythoncorrectnessno fixdefault: warnpython/ruff

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.

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 !=.

Reported
x = y = 1
x is "a"
x is not 1
b"" is x
x is None
x is True
x is y
x == "a"
x is [1]
(1, None) is x
x is (1, y)
...
python:
lint:
rules:
is-literal: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line is-literal in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff F632 full