Mon 2026.11.16
Gawain: a type hint check for Python variables
Today's pick: Gawain
Gawain is a product that requires type hints on Python variables as well as functions. It reports the places where a type hint is missing.
It is today’s pick because you can see a variable’s type without looking up a function’s definition.
- Found on
- Show HN
- Built with
- Rust, ruff_python_parser
The problem
In Python, you can write the type of a variable or a function in the code. This notation is called a type hint. Type hints are optional, and the code runs without them. According to its official docs, the type checker mypy infers a variable’s type from the first value assigned to it when there is no type hint. So a variable can pass the check without a type hint. A line such as pair = load() assigns a function’s return value and does not show the variable’s type. To learn the type, a reader has to look up that function’s definition or rely on an editor. The linter ruff has ANN rules that ask for type hints, but these rules cover functions only.
How it solves it
Gawain was posted to Hacker News as a Show HN on November 15, 2026. The maker is Marinho.
Gawain runs its check in two phases. The first phase finds each variable, parameter, return value and class attribute that has no type hint. For a constant with an uppercase name, Gawain requires Final. Final marks a value that must not change. If nothing is missing, the second phase runs the type checker ty or pyrefly to check that the type hints are correct. A variable passes without a type hint when its value alone shows its type. count = 0 and user = User("ada") both pass. The strict mode asks for a type hint on those variables too.
What is different
The first difference is where type hints are required. mypy and ruff’s ANN rules do not ask for type hints on variables. Gawain asks for them on variables and class attributes too, so the line that assigns a variable shows its type without a look at the function’s definition. The trade-off is that you also write types that mypy can infer. Even httpx 0.28.1, a library whose functions all have type hints, got 551 findings for variables and class attributes today.
The second difference is how Any is treated. Any is a type hint that accepts every type. mypy allows Any by default. According to its official docs, options such as --disallow-any-explicit forbid it. Gawain always reports Any in a type hint as an error. The README says the maker dislikes dict[str, Any] and built Gawain for that reason.
How it was built
- The repository has 17 commits from November 11 to November 15, 2026. The maker wrote all of them. There are 4 release tags, from v0.1.0 to v0.3.1.
- Gawain’s code is 5,021 lines of Rust. According to the README, it uses ruff’s parser, ruff_python_parser, to parse the Python code it checks.
Running it
I installed Gawain 0.3.1 with pip install "gawain[ty]" in a Python 3.13 virtual environment on Linux. I checked the README’s examples, files of my own and a public library.
- Install. Installation took 4 seconds and installed gawain 0.3.1 and ty 0.0.100.
- README examples. shop.py is an example with missing type hints. Gawain printed the same 6 findings as the README, in the same order. prices.py is an example that declares the wrong return type. For this file, ty reported 1 return type error, as in the README.
- Exit codes. A file with every type hint in place gave 0, and a file with errors gave 1. A missing file or a wrong option gave 2. When I passed
--checker pyreflywithout pyrefly installed, Gawain printed how to install it, and the exit code was 2. - Variables it does not check. Gawain reported
pair = load()as a variable with no type hint (GW001). When I split the same return value into two variables withfirst, second = load(), Gawain reported nothing. Gawain also did not report the variables offorandwithstatements, or a variable made with:=. According to docs/rules.md, Gawain does not report the names in an unpacking assignment or the targets offor,withand:=. - A real library. I checked the 23 files and 8,828 lines of httpx 0.28.1. Gawain reported 615 findings in total. They were 349 variables, 202 class attributes, 62 uses of Any and 2 constants. It reported 0 parameters and 0 return values.
- Speed. With the commands from docs/benchmarks.md, I checked the 591 files of the Python 3.13 standard library 30 times per command. The medians were 0.194 seconds for Gawain’s default mode, 0.139 seconds for the strict mode and 0.140 seconds for ruff’s ANN rules. In the README’s measurement, the default mode was also slower than the strict mode and ruff.
pair = load()
first, second = load()[presence]
edge.py:9:5 GW001 variable 'pair' has no type annotation
edge.py:11:5 GW001 variable 'count' has no type annotation (it is reassigned on line 12)
edge.py:23:1 GW010 constant 'LIMIT' must be annotated as Final[T]
edge.py:25:17 GW020 'Any' is not allowed in type annotations
edge.py:27:17 GW901 unused suppression 'GW001'
5 errors (presence). Type check skipped until presence errors are fixed.Not checked
- The type check with pyrefly. Today only ty was installed. The next step is to install pyrefly with
pip install "gawain[pyrefly]"and check prices.py. - The pre-commit hook. According to the README, the hook builds Gawain from source, so it needs Rust 1.97 or newer.
- The 1,847 files of the CPython 3.14 standard library that the README measured. Today’s run checked the 591 files of the Python 3.13 standard library installed from a Linux package.
Verdict
It works. The output matched the README’s examples, and Gawain found variables with no type hint in httpx. But it does not check variables assigned together, as in first, second = load(), or the variables that for and with statements define. It is worth trying if you are starting a new Python project.
What to take away
- If you build a checker, find out how many findings it reports on real code. Today Gawain reported about 1 finding for every 14 lines of httpx.
- Put the exact output next to each example in your docs. Today I compared the run with the README’s output and confirmed that they were the same.
- When you publish a benchmark, publish the commands too. Today I reran the README’s benchmark commands, and the default mode was slower than ruff, as in the README.
Getting started
pip install "gawain[ty]"gawain check src/
- You need
- Python 3.10 or later.
- Cost
- Free under the MIT license.
The maker says the type checker ty is in beta, so its results may change between versions. With the --no-types option, Gawain does not run ty and only checks that type hints are present.
Steps select 1 ran.
Progress
- Day 3Active
- Day 7Quiet
- Day 15Upcoming
- Day 30Upcoming
- Day 90Upcoming
- Day 180Upcoming
- Day 365Upcoming
Latest check Day 7, Sun 2026.11.22
- Commits since launch
- 3 → 6
- Stars
- 41 → 47
- Last commit
- 2026.11.15
No commits in this period.