Skip to content
Latchkey

mypy --strict: Turn On All Strictness Flags

mypy --strict is a shortcut that enables a curated set of strictness flags at once.

Strict mode is the usual target for new code. It is one flag, but it expands into roughly a dozen individual checks, so understanding what it implies matters when a CI run lights up.

What it does

mypy --strict enables a group of strictness options together, including --disallow-untyped-defs, --disallow-incomplete-defs, --check-untyped-defs, --warn-redundant-casts, --warn-unused-ignores, --warn-return-any, --no-implicit-reexport, and --disallow-any-generics among others. The exact set grows between mypy releases, so the same flag can report more on a newer version.

Common usage

Terminal
mypy --strict src/
# strict for the whole project but relax one rule
mypy --strict --allow-untyped-globals src/
# see the individual flags strict implies (helps debugging)
mypy --strict --help

Options

FlagWhat it does
--strictEnable the bundled strictness flags
--disallow-untyped-defsPart of strict: flag functions with no annotations
--warn-return-anyPart of strict: warn when returning a value typed Any
--warn-unused-ignoresPart of strict: flag type:ignore comments that do nothing
--no-implicit-reexportPart of strict: imported names are not re-exported by default

In CI

Because --strict expands differently across mypy versions, pin mypy in your lockfile so a routine dependency bump does not turn a green pipeline red. Cache .mypy_cache between runs so strict checks over a large tree stay fast.

Common errors in CI

Adopting --strict on an existing codebase floods the log with "Function is missing a type annotation" and "Returning Any from function declared to return X". Roll it out per module with per-module overrides rather than flipping it globally, or gate it behind --strict only for new packages.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →