3 ms·
In your example it should be def add_ints(a: int, b: int) -> Tuple[int | None, bool]. I’m not a fan of the Tuple return type. This is how golang does things a
by thebigspacefuck 3y ago
In your example it should be
def add_ints(a: int, b: int) -> Tuple[int | None, bool].
I’m not a fan of the Tuple return type. This is how golang does things and while it works there I don’t like seeing this in Python code because the Tuple tells you nothing unless you follow this convention and you have to add the Tuple annotation on top of every return type making it harder to read. I don’t see a need for it here since you’re already returning an Optional[int] (int | None in Python 3.10+). You could also raise a TypeError. Also your type checker should catch this if a or b are not an int, so you might feel safe returning a+b at this point and having the return type be simply int.