say I have a class:
class MyClass:
x: bool = True
def foo(self) -> int | str:
if self.x:
return 1
return '1'
I want to make this so the return type is int
when MyClass.x is True
and str
when MyClass.bool is False
. I know I can do conditional type hinting using @overload
based on arguments to the function/method, but I’m curious if there’s a way to have the typing be updated based on some kind of state.