The Python docs on Sequence mentions it supports concatenation here. The current Sequence (link) doesn't include __add__.
Please see the below code:
from typing import Sequence
# Can add List
list_1: Sequence[int] = [1, 2]
list_2: Sequence[int] = [3, 4]
assert len(list_1 + list_2) == 4
# Can't add range
range_1 = range(5)
range_2 = range(6)
concatenated_ranges = range_1 + range_2
Running this code throws a TypeError on the last line:
Traceback (most recent call last):
File "/path/to/foo.py", line 11, in <module>
concatenated_ranges = range_1 + range_2
TypeError: unsupported operand type(s) for +: 'range' and 'range'
Running mypy==0.931 on this I get the below errors:
path/to/foo.py:6:12: error: Unsupported left operand type for + ("Sequence[int]") [operator]
path/to/foo.py:11:23: error: Unsupported left operand type for + ("range") [operator]
Found 2 errors in 1 file (checked 21 source files)
I believe mypy is raising these errors per typeshed Sequence not implementing __add__.
So, there are two possibilities:
- Either: the Python docs should mention
__add__ isn't universally implemented for all Sequence
- Or
range should implement __add__ and we should add Sequence.__add__ should be added to typeshed
What do you think?
The Python docs on Sequence mentions it supports concatenation here. The current
Sequence(link) doesn't include__add__.Please see the below code:
Running this code throws a
TypeErroron the last line:Running
mypy==0.931on this I get the below errors:I believe mypy is raising these errors per typeshed
Sequencenot implementing__add__.So, there are two possibilities:
__add__isn't universally implemented for allSequencerangeshould implement__add__and we should addSequence.__add__should be added to typeshedWhat do you think?