How can I type annotate a tuple on a return where either of them might be None?
from typing import Tuple
def foo(bar:int) -> Tuple[int:
if bar > 10:
return 1, None
elif bar < 5:
return None, 1
else:
return 1, 2
CodePudding user response:
def foo(bar:int) -> tuple[int | None, int | None]:
if bar > 10:
return 1, None
elif bar < 5:
return None, 1
else:
return 1, 2
Like this ?