跳到内容

未使用的-方法-参数 (ARG002)

派生自 flake8-unused-arguments linter。

作用

检查实例方法定义中是否存在未使用的参数。

为什么这不好?

已定义但未使用的参数很可能是一个错误,应该删除以避免混淆。

如果一个变量是有意定义但不使用的,它应该以一个下划线为前缀,或者一些符合 lint.dummy-variable-rgx 模式的其他值。

示例

class Class:
    def foo(self, arg1, arg2):
        print(arg1)

建议改为

class Class:
    def foo(self, arg1):
        print(arg1)

Options (选项)