为什么序列是mypy中+不支持的操作数类型?

问题描述 投票:0回答:1

[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]:...

python typing mypy
1个回答
0
投票

根据文档,序列不一定实现__add__

© www.soinside.com 2019 - 2024. All rights reserved.