跳到内容

missing-return-type-private-function (ANN202)(缺少返回类型私有函数)

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

有时提供修复。

作用

Checks that private functions and methods have return type annotations.(检查私有函数和方法是否具有返回类型注解。)

为什么这不好?

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

示例

def _add(a, b):
    return a + b

建议改为

def _add(a: int, b: int) -> int:
    return a + b

Availability(可用性)

Because this rule relies on the third-party typing_extensions module for some Python versions, its diagnostic will not be emitted, and no fix will be offered, if typing_extensions imports have been disabled by the lint.typing-extensions linter option.(因为此规则在某些 Python 版本中依赖于第三方 typing_extensions 模块,如果 typing_extensions 导入已被 lint.typing-extensions linter 选项禁用,则不会发出诊断,也不会提供修复。)

Options (选项)