[mypy
给出的错误是Sequence[str]
运算符不支持+
:]]
# test.py from typing import Sequence def test(x: Sequence[str], y: Sequence[str]) -> Sequence[str]: return x + y
$ mypy test.py test.py:5: error: Unsupported left operand type for + ("Sequence[str]") Found 1 error in 1 file (checked 1 source file)
pytype给出了类似的错误:
$ pytype test.py [...] No attribute '__add__' on Sequence[str] or '__radd__' on Sequence[str] [...]
为什么
Sequence[str]
是+
不受支持的操作数类型?
mypy给出了一个错误,表明+运算符不支持Sequence [str]类型的操作数:#test.py来自输入import序列def test(x:Sequence [str],y:Sequence [str])->序列[str]:...
根据文档,序列不一定实现__add__
: