跳到内容

missing-return-type-static-method (ANN205)

源自 flake8-annotations 代码检查工具。

有时提供修复。

作用

检查静态方法是否具有返回类型注释。

为什么这不好?

类型注解是记录函数返回类型的好方法。 当与类型检查器一起使用时,它们还可以帮助捕获错误,通过确保任何返回值的类型以及调用者期望的类型都符合预期。

示例

class Foo:
    @staticmethod
    def bar():
        return 1

建议改为

class Foo:
    @staticmethod
    def bar() -> int:
        return 1