If you want to run post_init automatically after __init__ for this class and all inheriting classes you need to mess with how objects are instantiated using metaclasses. By default when you __call__ a class using A() it invokes a __new__ to create a new object and then an __init__ method of that object. You want to add the post_init to that sequence
class MyMetaclass(type):
def __call__(cls, *args, **kwargs):
new_obj = type.__call__(cls, *args, **kwargs)
new_obj.post_init()
return new_obj
class A(metaclass=MyMetaclass):
def __init__(self):
print('init called')
def post_init(self):
print('post init called')
You can verify that
>>> A()
init called
post init called
<__main__A at 0x7f3988e2c6a0>
self.post_init()inside__init__, but if you are not passing any extra args to.post_init, why can't use all statements inside__init__?post_init()is a time consuming function and takes a while to complete.and the class is to be instantiated inside another class as a property. So if i use it inside init() then I am unable to instantiate the class untill both methods have completed execution.init()and then call the second function.__is_fully_initialized, and you check at every function call. In case of need you do post_init(). (this trick is used on such slow case: doing work only when needed)