You might consider using the abc
Abstract Base Class module to mark __init__
as abstract, and then go ahead and invoke the superclass __init__
from the subclass (and, as DorElias suggested, give the superclass __init__
a trivial implementation of pass
):
from abc import ABCMeta, abstractmethod
class AbstractBase(object, metaclass=ABCMeta):
@abstractmethod # This method must be overridden...
def __init__(self):
print("...but can still be called via super by subclasses have shared construction logic")
pass
class RealChild(AbstractBase):
def __init__(self):
super().__init__() # Won't do anything, UNTIL the day you decide all subclasses of AbstractBase need shared logic
print('do stuff')
child = RealChild()
If you try to instantiate via parent = AbstractBase()
or parent = AbstractBase.__new__(AbstractBase)
, you'll get an error:
TypeError: Can't instantiate abstract class AbstractBase with abstract methods init
So you've got your uninstantiable abstract safety, but at the same time you are still well set up to alter all child class construction by altering base class construction, as is right and proper.