I've been working on a class that utilises abstract methods. However, I'm getting a mypy error for overwriting the function declaration in each child class. Could someone please explain to me how I can achieve the same effects, whilst also obeying mypy's desires.
from abc import ABC, abstractmethod
from typing import Any
class Base(ABC):
def __init__(self, *args: Any, **kwargs: Any) -> None:
# general init stuff for all classes...
self.myAbstractMethod(*args, **kwargs)
@abstractmethod
def myAbstractMethod(self, *args: Any, **kwargs: Any) -> None:
pass
class Child1(Base):
def myAbstractMethod(self, x: int, y: int) -> None:
print(x + y)
class Child2(Base):
def myAbstractMethod(self, a: str) -> None:
print(a)
Child1(1, 2)
Child2('hello stackoverflow')