Skip to content

Files

Latest commit

 

History

History
33 lines (23 loc) · 758 Bytes

super-init-not-called.md

File metadata and controls

33 lines (23 loc) · 758 Bytes

Pattern: __init__ not called from derived class

Issue: -

Description

Derived class should always call it's parent's __init__ method if available. Otherwise this could lead to partially initialized instance state causing unexpected behavior.

Example of incorrect code:

class Felinae(object):
    def __init__(self, subfamily):
        self.subfamily = subfamily

class Puma(Felinae):
    def __init__(self, subfamily, genus):
        self.genus = genus

Example of correct code:

class Felinae(object):
    def __init__(self, subfamily):
        self.subfamily = subfamily

class Puma(Felinae):
    def __init__(self, subfamily, genus):
        super(Puma, self).__init__(subfamily)
        self.genus = genus