Derived from the Pyflakes linter.
Fix is always available.
What it does#
is not comparisons against constant literals, like
integers and strings.
Why is this bad?#
is not comparators operate on identity, in that they check
whether two objects are the same object. If the objects are not the same
object, the comparison will always be
is not with
constant literals often works "by accident", but are not guaranteed to produce
the expected result.
As of Python 3.8, using
is not with constant literals will produce
!= to compare constant literals, which will compare
the values of the objects instead of their identities.
In preview, this rule will also flag
is not comparisons against
non-constant literals, like lists, sets, and dictionaries. While such
comparisons will not raise a
SyntaxWarning, they are still likely to be
incorrect, as they will compare the identities of the objects instead of
their values, which will always evaluate to