Explicit return in __init__ is Unproductive

Software ResiliencyCode Reliability

Explicit return in __init__ is Unproductive

This code insight counts one violation each time a return statement is encountered in a __init__ method.

5362

Why you should care

__init__ is a special Python method that is automatically called when memory is allocated for a new object. The sole purpose of __init__ is to initialize the values of instance members for the new object. Using __init__ to return a value implies that a program is using __init__ to do something other than initialize the object. This logic should be moved to another instance method and called by the program later, after initialization.

Business Impacts

 

Production Risk

CAST recommendations

References

https://www.quantifiedcode.com/knowledge-base/correctness/Returning%20a%20value%20from%20%60__init__%60/4RjRB5HW

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