use-is-for-singletons¶
Require identity operators when comparing singleton primitives.
Message¶
Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identity. Use is or is not instead.
References¶
Valid examples¶
if x: pass
if not x: pass
x is True
x is False
x is None
x is not None
Show more
x is True is not y
y is None is not x
None is y
True is x
False is x
x == 2
2 != x
"True" == "True"
"True" != "False".lower()
Invalid examples¶
x != True
Suggested fix
x is not True
x != False
Suggested fix
x is not False
x == False
Suggested fix
x is False
Show more
x == None
Suggested fix
x is None
x != None
Suggested fix
x is not None
False == x
Suggested fix
False is x
x is True == y
Suggested fix
x is True is y