I want implementations of my abstract class to accept an integer. For this, I can
from abc import ABC, abstractmethod
class Base(ABC):
@abstractmethod
def __init__(self, i: int):
pass
and then implementations will be like
class Sub(Base):
def __init__(self, i: int):
...
but since I can change the signature of __init__
without violating LSP, I can also
class Sub2(Sub):
def __init__(self, s: str):
...
and the signature of Base.__init__
is lost, and isn't enforced by the ABC
. That is, only direct descendants of Base
must have the same __init__
signature. If subclasses were strictly required to call superclass's __init__
methods, this wouldn't be a problem, because Sub2
would need to provide an int
to Sub
, but afaict that's optional.
Given this, does making __init__
abstract make sense? Or, more broadly, should subclasses ever be expected to have a given type signature?