Using “is” for anything but singleton can increase costs

CostSoftware AgilityCode Readability

Using “is” for anything but singleton can increase costs

Count one violation each time one of the operand of is (or is not) is not None, True or False.

5362

Why you should care

Testing the identity of two objects can be achieved in python with a special operator called  is. Most prominently it is used to check whether an variable points to  None. But the operator can examine any kind of identity. This often leads to confusion because equality of two different objects will return  False .

forgiveness : As some exception can be tolerated, a few percentage of “is” for checking identity of two objects other than singleton should be allowed in the model.

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