首页 > 解决方案 > Typehint 在 python mypy 中添加列表,其中列表具有不同的结构

问题描述

例子:

# check.py
x = [("a", "b"), ("c", "d")]
y = [("x", [("1", "2"), ("3", "4")])]
z = x + y

返回mypy check.py

check.py:5: error: Unsupported operand types for + ("List[Tuple[str, str]]" and "List[Tuple[str, List[Tuple[str, str]]]]")  [operator]
Found 1 error in 1 file (checked 1 source file)

我知道这个添加虽然有效 - 我不明白为什么它是“不支持的”,或者我应该怎么做才能输入这个。

标签: pythonmypypython-typing

解决方案


推荐阅读