Matheus Gomes 发布了名为 Gawain 的开源项目,这是一款旨在严格规范 Python 代码类型的检查工具 1。与 ruff 仅要求函数添加注解不同,Gawain 强制要求对代码中的所有变量、参数、返回值以及类属性进行类型注解 1。该工具集成了 Astral 的 ty 或 Meta 的 pyrefly 等类型检查器以验证注解的正确性,旨在消除未标注类型或使用模糊类型(如 dict[str, Any])的情况 1。
在功能配置上,用户可使用 --mode strict 标志进一步要求每一个赋值操作都包含明确的类型注解 1。安装方面,用户可通过 uv tool install "gawain[ty]" 安装默认版本,或通过指定 [pyrefly] 选项使用另一种后端 1。Gawain 定义了清晰的退出码规则:无问题时返回 0,发现错误时返回 1,若存在用法错误则返回 2 1。此外,该项目采用 MIT 许可证开源,并已在 CPython 3.14 标准库(包含 1,847 个文件、974,586 行代码)上进行过基准测试 1。
Developer Matheus Gomes has released Gawain, a new linting tool designed to mandate type annotations on all variables, parameters, return values, and class attributes within Python code 1. Unlike existing linters such as Ruff, which primarily focus on function-level annotations through its ANN rules, Gawain extends this requirement to variable assignments and class attributes 1. The summary indicates the tool aims to force the elimination of unannotated types, although specific examples like dict[str, Any] are not explicitly detailed in the key facts 1. The tool operates by integrating with established type checkers, specifically running either Astral’s ty or Meta’s pyrefly to verify that the provided annotations are correct 1.
Gawain offers a strict mode, activated via the --mode strict flag, which enforces an annotation for every single assignment in the codebase 1. Users can install the default version with uv tool install "gawain[ty]" or opt for the alternative using uv tool install "gawain[pyrefly]" 1. The software adheres to standard exit code conventions, returning 0 when no issues are detected, 1 when it reports errors, and 2 for usage errors 1. Released under the MIT license, the project was benchmarked against the CPython 3.14 standard library, comprising 1,847 files and 974,586 lines of code 1.
评论
还没有评论,欢迎留下第一条。