首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >预期类型'Union[ type,Tuple[Union[type,Tuple[Any,.],.]‘,得到'Tuple[ImgDirs,ImgDirs,ImgDirs]’

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

Stack Overflow用户
提问于 2021-03-12 05:34:16
回答 1查看 703关注 0票数 1

Python3.8.5

代码语言:javascript
复制
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 ( 2020.3)显示了mysmatch类型的错误。

代码语言:javascript
复制
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.

你能帮我纠正一下吗?

EN

回答 1

Stack Overflow用户

发布于 2021-03-12 08:21:04

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

否则,我们需要更多关于general.ImgDirs中的内容的详细信息:它们是类、来自typing模块的继承还是一些基本类型的组合?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66594702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档