Rule Definition
Accessing uninitialized variables is a typical source of errors and unexpected behaviour. Overriding the __init__ method of an ancestor class without initializing it can leave unitialized instance members.
Remediation
Initialize ancestors when overriding __init__ using consistently non-super methods or super() if their ancestors do.
Violation Code Sample
>>> class A:
>>> def __init__(self):
>>> self.x = 3
>>> self.y = 14
>>>
>>> class B(A):
>>> def __init__(self):
>>> self.y = 2
Fixed Code Sample
>>> # approach (1)
>>> class B(A):
>>> def __init__(self):
>>> super().__init__() # in Python2: super(B, self).__init__()
>>> self.y = 2
>>>
>>> # approach (2)
>>> class B(A):
>>> def __init__(self):
>>> A.__init__()
>>> self.y = 2
Related Technologies
Technical Criterion
CWE-456 - Missing Initialization of a Variable
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.