gpt4 book ai didi

python - 将 *args 作为列表传递时如何禁用 "E1120: No value for argument if"的 pylint 报告

转载 作者:行者123 更新时间:2023-12-05 04:50:04 25 4
gpt4 key购买 nike

我有以下代码部分会触发 Pylint 错误“E1120:如果参数没有值”。

framework/packages/create_network.py:79:21: E1120: No value for argument 'bridge1' in function call (no-value-for-parameter)

Pylint 是否有可以绕过针对此特定情况的此检查的标志?我正在寻找一种不需要更改代码本身并且是传递给 Pylint 的参数的解决方案。

在我的回答中,我会在代码中放置我熟悉的标志,即注释。

案例描述

当将解压缩列表作为值传递给由名称而不是 *args 定义的参数时,会发生这种情况。

脚本传递一个列表

bridges = create_bridge(interface1, interface2)   # Returns an array of 4 values
routers = get_routers(*bridges) # Unpacks the array and passes values to 4 parameters

函数签名是

def get_routers(bridge1, bridge2, bridge3, bridge4):

最佳答案

这可以通过禁用导致问题的特定行的 E1120 特定检查来解决。

在这种情况下,代码现在将在

bridges = create_bridge(interface1, interface2)   # Returns an array of 4 values
#pylint: disable = no-value-for-parameter # Disables the pylint check for the next line
routers = get_routers(*bridges) # Unpacks the array and passes values to 4 parameters

我不喜欢这个解决方案,因为它迫使我改变自己。在将 Pylint 作为可选标志运行时,我更愿意禁用此检查,只是为了将列表解包到参数。

关于python - 将 *args 作为列表传递时如何禁用 "E1120: No value for argument if"的 pylint 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67381591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com