cdw*_*son 5 python typing mypy
mypy给出的错误Sequence[str]不是该运算符支持的操作数类型+:
# test.py
from typing import Sequence
def test(x: Sequence[str], y: Sequence[str]) -> Sequence[str]:
return x + y
Run Code Online (Sandbox Code Playgroud)
$ mypy test.py
test.py:5: error: Unsupported left operand type for + ("Sequence[str]")
Found 1 error in 1 file (checked 1 source file)
Run Code Online (Sandbox Code Playgroud)
pytype 给出了类似的错误:
$ pytype test.py
[...]
No attribute '__add__' on Sequence[str] or '__radd__' on Sequence[str]
[...]
Run Code Online (Sandbox Code Playgroud)
为什么 是Sequence[str]不受支持的操作数类型+?
根据文档,序列不一定实现__add__:
https://docs.python.org/3/glossary.html#term-sequence
不支持串联的一个示例Sequence是range.
| 归档时间: |
|
| 查看次数: |
3004 次 |
| 最近记录: |