I have a function that takes either a list of five ints or five ints as a tuple (*argv).
Here's my function heading:
def __init__(self, *argv: Union[int, list]) -> None:
Later in this function I check the contents of this tuple to see if it's a list or five individual ints.
if type(argv[0]) == int:
self._l1 = [argv[0], argv[1], argv[2], argv[3], argv[4]]
else:
self._l1 = argv[0]
By this point in the code l1 is a list. self._l1 is definitely a list, it's no longer an int, it's a list.
However later in my code when I run this line:
self._myvar = self._l1.count(1)
I am returned this error from MyPy
Incompatible types in assignment (expression has type "Union[int, List[Any]]", variable has type "List[Union[int, List[Any]]]")
Am I typing this wrong, what do I need to type this as? I've tried so many different types and keep getting errors.
As far as I can tell though my input is a tuple that will either contain a list of ints or five ints. I'd assume it's something like Union[Tuple[List[int]], Tuple[int, ...]] or just Union[List[int], int] or Union[List[int], Tuple[int, ...]], or something similar, but none of these are working for me.