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?
This is close to python/mypy#5492. I found a fix in #2404.
fix list concatenation (#2404)
fix list concatenation (python#2404)
#2404 has been reverted. Do we have a solution for this issue?
+1 from microsoft/pyright#1777
Activity
JelleZijlstra commented on Aug 19, 2018
This is close to python/mypy#5492. I found a fix in #2404.
fix list concatenation (#2404)
fix list concatenation (python#2404)
wy193777 commented on May 28, 2019
#2404 has been reverted. Do we have a solution for this issue?
tamuhey commented on Apr 20, 2021
+1 from microsoft/pyright#1777