繁体   English   中英

Python 列表解包触发 pylint 'No value for argument' 警告

[英]Python list unpacking trigger pylint ' No value for argument' warning

这个问题和Pylint false positive when unpacking sys.argv一样,但是没有答案。

我有以下 function:

def join(*paths_to_join: str) -> str:
    """Join and returns a normalized path

    Args:
        *paths_to_join (str): All paths to be joined, as an arbitrary number of strings

    Returns:
        The normalized joined path
    """

    return os.path.normpath((os.path.join(*paths_to_join))

这会触发以下pylint警告:

E1120: function 调用中参数 'a' 没有值(参数无值)

这是真正的警告还是误报? 除了禁用它我还能做些什么吗?

这是一个有效的警告。 os.path.join()至少需要一个参数,但您的 function 不需要。 所以paths_to_join可能是空的。

将您的 function 更改为类似于os.path.join()

def join(first: str, rest: List[str]): -> str:
    return os.path.normpath(os.path.join(first, *rest))

暂无
暂无

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

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