Python3.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 ( 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.你能帮我纠正一下吗?

发布于 2021-03-12 08:21:04
PyCharm抱怨(general.ImgDirs.RASTER, ...)不符合isinstance的预期签名,后者如果由Union[type, Tuple[Any, ...]]组成,则接受元组。
否则,我们需要更多关于general.ImgDirs中的内容的详细信息:它们是类、来自typing模块的继承还是一些基本类型的组合?
https://stackoverflow.com/questions/66594702
复制相似问题