Consider the case when I have different classes implementing the same method while returning different types.
class A:
def method(self) -> float:
return 3.14
class B:
def method(self) -> str:
return 'a string'
def do_method(x):
return x.method()
r = do_method(A())
reveal_type(r) # Revealed type is 'Any'
Mypy is not being able to infer the exact return type of function do_method() which depends on its argument x. How can I help Mypy achieve this?
Note: Please also consider that number of such classes that I want to use with the function do_method() is too many, so one doesn't want to change them all.