Gawain is a new Python utility designed to enforce strict type annotation practices across an entire codebase. It mandates type hints not only for function parameters and return values but also for all local variables and class attributes. This goes beyond the scope of existing tools like ruff's ANN rules or flake8-annotations, which typically focus only on function-level annotations.
The tool operates in two main phases. First, it checks for the presence of type annotations on all declared elements. If any annotations are missing, Gawain reports these as errors and skips the type checking phase. Once all presence errors are resolved, Gawain proceeds to run a specified type checker, such as ty (the default) or pyrefly, to verify the correctness of the provided types against the code's logic.
The developer created Gawain to combat the common use of `dict[str, Any]` and similar constructs that bypass explicit type definitions. By requiring annotations everywhere, Gawain aims to reduce the reliance on type inference by IDEs or type checkers, promoting more explicit and maintainable codebases. For example, it would flag a constant like `PORT = 8080` for needing `Final[int]`.
Gawain can be installed using `pip` or `uv`. Users can choose their preferred type checker by installing Gawain with specific extras, such as `gawain[ty]` or `gawain[pyrefly]`. The default checker is ty, pinned to version 0.0.100 with its extra. Pyrefly is pinned to version 1.4.1. The checker can also be specified via a configuration file or command-line arguments.
✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →
One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.
One email a day. Unsubscribe in one click, any time.
Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.
▶ Play today's briefNew every morning, and the back catalogue is archived by date.
Gawain is a new Python tool that requires type annotations on all variables, parameters, return values, and class attributes, then runs a type checker like ty or pyrefly to verify correctness. Unlike other tools that focus only on function annotations, Gawain extends this requirement to all variable declarations, aiming to reduce implicit `Any` types.