mypy:Collection [str]替换嵌套结构类型吗?

时间:2019-10-17 12:54:40

标签: python mypy

我有一个data变量,如果正确键入,应如下所示:

data: List[Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]] = []

但是当我尝试使用以下代码追加到此列表时:

info = {"spaghetti": [{"value": "foo", "test": "bar"}]}
my_data = {
        "Name": name,
        "_info": info,
    }
data.append(my_data)

Mypy告诉我:

Argument 1 to "append" of "list" has incompatible type "Dict[str, Collection[str]]"; expected "Dict[str, Union[str, Dict[str, List[Dict[str, str]]]]]"

现在,Union[str, Dict[str, List[Dict[str, str]]]]等同于Collection[str]的可能性如何?

0 个答案:

没有答案