跳到内容

str-or-repr-defined-in-stub (PYI029) | 在存根中定义了 __str__ 或 __repr__

源自 flake8-pyi 代码检查器。

修复总是可用的。

作用

Checks for redundant definitions of __str__ or __repr__ in stubs. (检查存根中 __str____repr__ 的冗余定义)

为什么这不好?

Defining __str__ or __repr__ in a stub is almost always redundant, as the signatures are almost always identical to those of the default equivalent, object.__str__ and object.__repr__, respectively. (在存根中定义 __str____repr__ 几乎总是多余的,因为它们的签名几乎总是与默认等效项 object.__str__object.__repr__ 的签名相同。)

示例

class Foo:
    def __repr__(self) -> str: ...