Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mypy:Collection[str]替换嵌套结构类型?_Python_Mypy - Fatal编程技术网

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

Python mypy:Collection[str]替换嵌套结构类型?,python,mypy,Python,Mypy,我有一个数据变量,如果输入正确,应该如下所示: 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: 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]

注意
Dict[str,Any]
Collection[str]
的子集,因为
Dict
实现了
Collection
接口。将类型注释(或显式的
cast
)添加到
info
)有帮助吗?注释
info
没有帮助,但如果我注释
my_数据
,则没有更多警告。