-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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] + xfails 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
| def __add__(self, x: List[_T]) -> List[_T]: ... |
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?
tamuhey and smackesey
Metadata
Metadata
Assignees
Labels
No labels