You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Better messages when type is incompatible due to invariance #3352
Users are often confused by compatibility of invariant collection types. Here is an example from #3351:
fromtypingimportList, Uniondefmean(numbers: List[Union[int, float]]) ->float:
returnsum(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?
Activity
ilevkivskyi commentedon May 19, 2017
Isn't this a duplicate of #1115?
quartox commentedon May 22, 2017
I will start looking at this.
Add informative notes to invariant function arguments (#3411)
ilevkivskyi commentedon Aug 19, 2017
This is now fixed by #3411