我有一个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]
的可能性如何?