1

给定以下代码:

# check.py
import attr
from attr._make import Attribute


@attr.frozen
class Example:
    x: int = attr.ib()

    @x.validator
    def _validate_x(self, _: Attribute, value: int) -> None:
        assert value > 0

运行pylint check.py将返回:

************* Module check
check.py:12:4: R0201: Method could be a function (no-self-use)

授予此代码是一个非常人为的示例,但我不确定我应该如何更改代码以取悦此消息?

编辑

以下工作要忽略:

@attr.frozen
class Example:
    # pylint: disable=no-self-use
    x: int = attr.ib()

    @x.validator
    def _validate_x(self, _: Attribute, value: int) -> None:
        assert value > 0
4

1 回答 1

2

尝试这个:

# pylint: disable=R0201
于 2021-07-25T00:16:41.083 回答