簡體   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