跳到内容

未使用的私有协议 (PYI046)

源自 flake8-pyi 代码检查器。

作用

检查是否存在未使用的私有 typing.Protocol 定义。

为什么这不好?

已定义但未使用的私有 typing.Protocol 可能是个错误。 应该使用它、使其公开或删除以避免混淆。

示例

import typing

class _PrivateProtocol(typing.Protocol):
    foo: int

建议改为

import typing

class _PrivateProtocol(typing.Protocol):
    foo: int

def func(arg: _PrivateProtocol) -> None: ...