‘Not…is’ syntax can be unreadable

CostSoftware AgilityCode Readability

‘Not…is’ syntax can be unreadable

Count one violation each time the not … is syntax is encountered.

bad

some_list = None
if not some_list is None:
do_something()

good

some_list = None
if some_list is not None:
do_something()

Note: there is no violation if the operators “and”, “or”, && or ||
are between “not” and “is” because that means that “not” and “is ”
are in different elementary conditions:

if not toto and titi is tata:
do_anything()

5362

Why you should care

In Python readability counts. That is why if-checks should be written with the reader in mind. Therefore it is generally better to write a condition just like one would write prose.

Business Impacts

It is recommended to avoid these in order to ensure the code is more readable and cost effective.

Cost

CAST recommendations

References

https://www.quantifiedcode.com/knowledge-base/readability/%60not%20…%20is%60%20used%20instead%20of%20%60is%20not%60/4ORGpHyx

5362

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works

c