Python itself checks types only when the line runs. mypy reads the type annotations and finds the errors beforehand – in the course two deliberately planted ones in a throwaway file.
Symptom
uv run --with mypy mypy src; echo "exit=$?"
src/logsum/typo.py:3: error: Argument "since" to "summarize" has incompatible
type "str"; expected "datetime | None" [arg-type]
src/logsum/typo.py:4: error: Unsupported operand types for + ("int" and "str")
[operator]
Found 2 errors in 1 file (checked 6 source files)
exit=1
uv run --with mypy starts mypy in a throwaway environment without installing it.
Diagnosis
The two lines of the checked file.
from logsum.stats import summarize s = summarize([], since="2026-10-10T08:30") print(s.total + "Anfragen")
Causes
[operator]int + str
s.total is a number, "Anfragen" (“requests”) a string. Python would abort with TypeError at runtime.
[arg-type]String instead of datetime
summarize expects a datetime or None for since but gets a string.
Fix
rm src/logsum/typo.py uv run --with mypy mypy --strict src Success: no issues found in 5 source files
Don't: Silence errors with # type: ignore. The runtime errors still come.
Python hands-on, Day 2: functions, dataclasses, types and mypy with the logsum tool.
Go to day 2 →
FAQ
Do I have to install mypy?
No. uv run --with mypy mypy src starts mypy in a throwaway environment.
What does --strict add?
--strict turns on extra checks such as missing annotations. In the course logsum passes it without findings.