跳到内容

no-staticmethod-decorator (PLR0203)

源自 Pylint 代码检查工具。

修复总是可用的。

此规则不稳定且处于预览状态。使用需要 --preview 标志。

作用

检查是否在未使用装饰器的情况下声明了 staticmethod。

为什么这不好?

为了保持一致性和可读性,建议使用装饰器。

示例

class Foo:
    def bar(arg1, arg2): ...

    bar = staticmethod(bar)

建议改为

class Foo:
    @staticmethod
    def bar(arg1, arg2): ...