Show HN: Gawain – Require type hints on all Python variables github.com · 28 poi...

@show

Show HN: Gawain – Require type hints on all Python variables github.com · 28 points · 9 comments · HN thread

TL;DR gawain is a Python linter that requires type annotations on variables, parameters, return values and class attributes, then runs a type checker (ty by default, or pyrefly) on the annotated code. The README shows examples of the rule codes GW001 to GW020, a default 'obvious' mode and a strict mode, and benchmarks against ruff ANN and flake8-annotations on the CPython 3.14 standard library. The Show HN post was a short pitch from the author, who says they built it because they hate dict[str, Any].

  • Requires annotations on variables, parameters, returns and class attributes, which ruff ANN and flake8-annotations do not check for variables.
  • Runs ty (default, pinned to 0.0.100) or pyrefly (pinned to 1.4.1) after the annotation checks pass, and reports type errors.
  • Default 'obvious' mode skips annotations for literals, literal containers and constructor calls that are never reassigned; 'strict' mode requires an annotation on every assignment.
  • Rule codes: GW001 unannotated variable, GW002 parameter, GW003 return, GW004 class attribute, GW010 constant not Final[T], GW011 bare Final, GW020 Any in an annotation.
  • Benchmark on CPython 3.14 stdlib (one machine): gawain about 0.36 to 0.46 s with --no-types, ruff ANN 0.35 s, flake8-annotations 11.4 s.
  • Warns that ty is in beta and its diagnostics may change between versions; exit codes are 0 clean, 1 errors, 2 usage or checker failure.

Discussion The thread is small and mostly light-hearted. Several commenters enjoyed the Arthurian name and quoted the original Middle English Sir Gawain and the Green Knight text, and a few praised the tool's attitude. The substantive exchanges are about whether strict typing belongs in Python at all: some say they moved to typed languages instead, one suggests stopping Python altogether, and another asks for strict typing that also runs fast, pointing to mypyc. One commenter sees agent-written code and blocking lint hooks as a way to get fully typed codebases. The mood is amused and mildly skeptical rather than hostile.

  • Enforced types are essential for long-lived codebases (some): Commenters say types make code safer to maintain and that they stopped using Python or started preferring typed languages after seeing the benefit. One suggests combining strict linting with agent-written code in a blocking pre-commit hook.
  • Python is the wrong tool for strict typing (a few): A few suggest moving to another language rather than adding more annotation burden, and one jokingly suggests stopping writing Python. Another objects that Python syntax gets more verbose with annotations.
  • Want strict typing that also runs fast (a few): One commenter wishes for a strictly typed Python that is also fast, and another suggests mypyc as a route, while admitting they have not tried it.
  • Amused by the Arthurian naming and quotes (a few): Several comments focus on the project name, quoting the original Middle English poem and suggesting the README include a quote about covenants.
  • Mild objection that Python already reads like English (a few): One commenter pushes back on the claim that Python syntax is ugly, arguing it is the closest mainstream language to English.

#python #typing #linter #staticAnalysis #developerTools