Closed
Description
Users are often confused by compatibility of invariant collection types. Here is an example from #3351:
from typing import List, Union
def mean(numbers: List[Union[int, float]]) -> float:
return sum(numbers) / len(numbers)
some_numbers = [1, 2, 3, 4]
mean(some_numbers) # Argument 1 to "mean" has incompatible type List[int];
# expected List[Union[int, float]]
It might be helpful to add a note with more details, since the message doesn't really provide enough context to start googling for help. Here is one idea:
program.py:23:note: "List" is invariant -- see <link to docs>
program.py:23:note: Maybe you can use "Sequence" as the target type, which is covariant?