While working through a custom django mixin, I came across code with the following structure:
class A:
def method(self, i): # this is a method provided by django, so can't easily change this signature
print(f"A: {i}")
class B:
def method(self, i: int): # with type hint
print(f"B: {i}")
super().method(i)
class C(B, A):
pass
# at some point
C().method(0)
mypy gives error: "method" undefined in superclass
. For now, the workaround I use is to treat method
as dynamically typed (i.e drop the int
). Is it possible to (or does it make sense to) add type annotations so method
is treated as statically typed? Thanks!