Closed
Description
Using mypy==0.620
and Python 3.6.6, the following code:
from typing import List, Optional
x: List[Optional[int]] = [1, 2, 3]
[None] + x
fails with:
a.py:4: error: Unsupported operand types for + ("List[None]" and "List[Optional[int]]")
This is presumably because lists are invariant w.r.t their generic parameter, and the declration requires a List
of the same type
typeshed/stdlib/3/builtins.pyi
Line 619 in 4e40b03
I don't know what the right solution here is -- can we just replace the x: List[_T]
with x: List[_T_co]
and make it covariant? Or doe we need another typevar _U = TypeVar("U", bound=_T)
or something?
Metadata
Metadata
Assignees
Labels
No labels