I have a function that will return a single response as an int if the count passed to the function is 1. Elsewise, a list of responses is returned.
I tried to type this using overloads, however I get an error from MyPy: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
I've researched, and it seems like the problem is that a count of 1 would satisfy both overloads, which is not allowed.
Does anyone know how to get around this?
@overload
def read_and_check(self, address: int, count: Literal[1] = 1) -> int: ...
@overload
def read_and_check(self, address: int, count: int) -> list[int]: ...