From microsoft/pyright#1777
[0] + ["a"] is not allowed in any type checker (e.g. pyright, mypy) because the type annotation of list.__add__ is defined as follows:
class list(MutableSequence[_T], Generic[_T]): ... def __add__(self, x: List[_T]) -> List[_T]: ...
This annotation prohibits heterogeneous concatenation, although it is actually allowed in runtime. I think the annotation should be as follows to solve this problem:
class list(MutableSequence[_T], Generic[_T]): ... def __add__(self, x: List[_S]) -> List[Union[_T, _S]]: ...
See #3183 for some past attempts.
Also related: #2383
Activity
JelleZijlstra commented on Apr 20, 2021
See #3183 for some past attempts.
tamuhey commented on Apr 20, 2021
Also related: #2383