Rule Definition
Since Python version 2.3 the "is not" keyword pair is an operator in its own right. The expression "x is not y" is equivalent to "not (x is y)" and because of operator precedence rules it can be also expressed without parenthesis as "not x is y". The latter form can be a source of unexpected logical behavior as it appears reversed with respect to the natural English construction "is not". Thus it is recommended to use the "x is not y" form.
Remediation
Highlight operator precedence by adding parenthesis or even better rewrite the identity comparison with the "is not" operator.
Violation Code Sample
>>> if not x is y:
>>> ...
Fixed Code Sample
>>> if not (x is y):
>>> ...
>>>
>>> # Or preferably
>>>
>>> if x is not y:
>>> ...
Related Technologies
Technical Criterion
Documentation - Style Conformity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.