Show HN: Gawain – Require type hints on all Python variables
Gawain is a new Python type annotation checker that enforces explicit type hints on all variables, parameters, returns, and class attributes.
summary is enough The README provides a clear overview of the rules and benchmarks, making a quick read sufficient unless you want to adopt the tool.
summary
Gawain is a Rust-based CLI tool designed to enforce strict type annotations across Python variables, function signatures, and class attributes. Built on top of parsers and type checkers like ty or pyrefly, it goes beyond standard linters by demanding explicit types where inference would normally apply. It provides an obvious mode for literal assignments and a strict mode requiring annotations everywhere. The author built it specifically to eliminate loose typing habits in large Python codebases.
key points
- Enforces type annotations on variables, parameters, returns, and class attributes using underlying checkers like ty or pyrefly.
- Features an obvious mode that permits inferred types for literals, alongside a strict mode requiring annotations on every assignment.
- Outperforms older tools like flake8-annotations significantly on large codebases during benchmarks.
who should read it
Python developers and maintainers interested in strict static analysis and type safety.
discussion skeptical
consensus
Commenters are deeply divided on whether forcing strict type hints ruins Python's dynamic flexibility or helps manage massive legacy codebases.
pushback
A minority argues that strict type enforcement combined with pre-commit hooks and AI agents successfully eliminates entire classes of runtime errors.
I wish the people spearheading the charge to integrate static typing into Python had borne in mind the old aphorism about not being able to make an octopus by nailing legs to a dog.
Python is a great dynamic language. There are many great statically typed languages. Why does every great dog have to become a half-assed octopus?
It eloquently captures the core frustration of trying to shoehorn static typing into a dynamic language with a striking metaphor.
Generated by an LLM from the article and thread. Check the sources before relying on it.