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

mypy is giving an error that Sequence[str] is not a supported operand type for the + operator:

# 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]

[...]

Why is Sequence[str] an unsupported operand type for +?

评论