
gawain
Type annotations for variables, not just functions
At a glance
Gawain is a Python checker that requires type annotations on variables, parameters, returns and class attributes, then runs a type checker.
- MITOpen source license
- PythonType annotation checks
- Annotations on variables, not only functions
- Strict mode for every assignment
- Pre-commit hook included
Works with typyreflypre-commit
Alternative to ruff, flake8-annotations
- Pricing
- Free
- Platforms
- CLI
- Category
- Developer Tools
- Website
- github.com/matheuzgomes
- Last checked

What it does
Gawain is a type annotation checker for Python. Other tools ask for annotations on functions only, and type checkers infer the type of a variable that has no annotation. Gawain also asks for annotations on variables and class attributes, and then runs a type checker to confirm the types are correct.
It reports what is missing, with a code for each rule. A variable with no annotation, a parameter, a function with no return type and a class attribute each have their own code, and a constant should be annotated as final.
How it works
- Install gawain with the extra for the type checker you want.
- Run the check on a source folder, which first checks the annotations and then the types.
- Read the report, or ask for JSON output to feed into other tools.
What makes it different
The default mode allows a name to go without an annotation when its value has an obvious type and it is never assigned again. A strict mode asks for an annotation on every assignment. It also runs as a pre-commit hook, so the check can run before each commit.
Good to know
The default type checker is ty, which is in beta, so its messages may change between versions. You can switch to pyrefly, or run only the annotation checks with a flag. The project is open source under the MIT license, and it is free to use.
Who it's for
Python developers who want full type annotations in their project
Typical uses
- Add annotations to a Python project that uses a type checker
- Enforce strict typing on a team codebase in a pre-commit hook
- Find variables that type checkers would otherwise infer silently
Features
- Annotation checks for variables, parameters, returns and class attributes
- A type checker run after the annotation checks
- Default and strict modes
- Pre-commit hook support
- JSON output for tools
- Works with ty or pyrefly
Pricing
Free
Free to use. The project is open source under the MIT license.
Limitations
- The default type checker, ty, is in beta, and its messages may change.
- It checks Python code only.
FAQ
Is gawain free?
Yes. It is open source under the MIT license.
Which type checker does it use?
Ty by default, with pyrefly as an option, or annotation checks alone with a flag.