为什么 PyCharm 会给我 "Duplicate *arg" 的警告?

Why does PyCharm give me warnings for "Duplicate *arg"?

使用 Python 3.5,我将多个多维列表插入 MySQL 查询,该查询将多行插入 table。这是我的执行代码片段:

for x, y, z, i in zip(list1, list2, list3, list4):
    cursor.execute(add_related_accounts_query.format(x[0], *y, *z, *i))

查询工作正常,但 PyCharm 给我这个警告:

Duplicate *args

This inspection reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments and incorrect argument order.

如果我按 Alt+Enter 通过 PyCharm 修复警告,它会消除 *z, *i 和然后查询不再有效。

如果解决方案破坏了我的脚本,有人可以解释为什么会发出此警告吗?

PyCharm 可能只希望您将一个 *args 列表传递给函数。您可以在扩展它们之前添加 x、y 和 i,我想 pycharm 会停止抱怨。

cursor.execute(add_related_accounts_query.format(x[0], *(y+z+i))

尽管如此,您必须对 pycharm 警告持保留态度。它并不总是完美的。它有一组注释,您可以在这样的行之前放置,以强制它忽略警告。