简体   繁体   English

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

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

This question is the same as Pylint false positive when unpacking sys.argv but it had no answer.这个问题和Pylint false positive when unpacking sys.argv一样,但是没有答案。

I have the following function:我有以下 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))

This triggers the following pylint warning:这会触发以下pylint警告:

E1120: No value for argument 'a' in function call (no-value-for-parameter) E1120: function 调用中参数 'a' 没有值(参数无值)

Is it a real warning or a false positive?这是真正的警告还是误报? Can I do something else than disable it?除了禁用它我还能做些什么吗?

This is a valid warning.这是一个有效的警告。 os.path.join() requires at least one argument, but your function doesn't. os.path.join()至少需要一个参数,但您的 function 不需要。 So paths_to_join could be empty.所以paths_to_join可能是空的。

Change your function to be similar to os.path.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