繁体   English   中英

预期类型 'Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]',得到 'Tuple[ImgDirs, ImgDirs, ImgDirs]'

[英]Expected type 'Union[type, Tuple[Union[type, Tuple[Any, …]], …]]', got 'Tuple[ImgDirs, ImgDirs, ImgDirs]' instead

Python 3.8.5

def delete_catalogue_from_media(instance,
                                file_type: Union[general.ImgDirs.RASTER,
                                                 general.ImgDirs.SVG,
                                                 general.ImgDirs.FAV]) -> None:
    # //@formatter:off
    # Assertions {
    assert isinstance(file_type, (general.ImgDirs.RASTER, general.ImgDirs.SVG, general.ImgDirs.FAV))
    # } Assertions
    # //@formatter:on

问题

IDE(Pycharm 社区 2020.3)显示有关 mysmatch 类型的错误。

Expected type 'Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]]', got 'Tuple[ImgDirs, ImgDirs, ImgDirs]' instead 
 Inspection info: This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations.

你能帮我纠正这个吗?

在此处输入图像描述

PyCharm 抱怨(general.ImgDirs.RASTER, ...)不符合isinstance的预期签名,如果由Union[type, Tuple[Any, ...]]组成,它接受元组。

typing ,我们需要有关general.ImgDirs情况的更多详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM