Is there a way to make a generic class A[T], which has a function that inherits the type for the same function in T?
I want to make something like these 2 classes:
class A[T]:
...
def a(self):
...
class B(A):
def a(self, a: int, b:int):
...
and have A[B].a's type be (self: B, a: int, b: int) -> None, instead of (self: A) -> None. Is there a way to do this without repeating the type hints in the definition of the B class?
def demo(a: A): return a.a()fails fordemo(B()), because the subclass method has required arguments the superclass method does not..A[B]– "this is sort of anA, but you can't use it without knowing it's really aB" – then it might be clearer to make the base class method a "private" helper with a different name, and have the static type of your object be the concrete typeB.A[B]-Adoesn't currently useT, and why would that be its own subclass? Maybe you want something like this, but note that tells you the same thing for this specific case:B's implementation ofais not compatible with the supertype.