- How you use it
- You ask for it
- What it can do
- writes files · runs shell
- What's inside
The option
| Option | ASkill · v1.0.0Gradual mypy module profile |
|---|---|
| How you use it | You ask for it |
| What it can do | writes files · runs shell |
| What's inside |
What this thread does
Do first: enable disallow_any_unimported = true and inspect unresolved imports before widening boundary types.
Short answer
As of November 2026, use mypy 2.4.1, October 28 release. Prefer maintained stubs, then a small local stub or typed adapter. Validate external data before giving it a trusted result type; use a checked result type.
Choose / don't choose
- Local stub: choose when you can describe the dependency's actual call signatures; don't invent signatures merely to silence callers. Stubs override matching implementation files (stub guide).
- Protocol: choose when consumers need a small structural interface rather than one vendor's concrete class. Annotate the adapter's public interface with
typing.Protocol; don't treat structural typing as payload validation (protocol guide). - Gradual rollout: choose one widely imported module at a time; don't suppress all imports globally. mypy's existing-code guide support staged enforcement and CI.
Not for: Python unit-test quality or mutation testing; see mutation-testing-agent-written-tests.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
disallow_any_unimported | true; default false; reject annotation components degraded by unfollowed imports | mypy current docs | config |
ignore_missing_imports | Global false; temporary true only in override matching imported dependency, not the caller | mypy current docs | config |
disallow_untyped_calls | true for typed callers; default false | mypy current docs | config |
mypy_path | Local stub directories; preserve the dependency's module hierarchy | mypy current docs | config, stub guide |
warn_return_any | true at typed adapters; default false | mypy current docs | config |
check_untyped_defs / disallow_untyped_defs | Enable first globally, second in adopted modules; both default false | mypy current docs | config |
Order of operations
1. Record the current diagnostics, pin the checker in CI and adopt widely used modules first. Keep ignore_errors = true confined to named legacy modules; move one into enforcement at a time, then make strict = true the goal (existing-code guide). 2. Resolve the import in the same interpreter environment as the checker. Install a maintained stub package when available. Otherwise create a local stub with exact argument and return annotations and ellipsis bodies, configure its directory, then remove that import's suppression (imports, stubs). 3. Keep the third-party call inside a typed adapter. Validate unknown payload shape and values before returning the application's concrete type. Use a Protocol for the capabilities consumers require; an unchecked cast only asserts a static belief (typing). 4. Run the pinned checker on both valid calls and an intentionally wrong argument in a disposable consumer. Expect the latter to fail; inspect config diffs so an ignore did not create the apparent improvement. Review inferred annotations manually.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Call to untyped function "bad" in typed context | Typed caller reaches an unannotated callable | Add accurate local .pyi signature; keep disallow_untyped_calls on | error reference, stubs |
Returning Any from function declared to return "str" | Adapter leaks an untyped return | Validate and narrow, then return the declared type | error reference |
import-untyped | Call exclusions do not supply missing package types | Distinguish import diagnostics from call diagnostics; install/write stubs | user report, imports |
The dated mypy issue describes exclusions failing to remove import-related diagnostics; it is evidence for separating those checks, not a blanket reason to disable them.
Notes and limits
- The linked source does not confirm: Tim Hopper guide updated October 23 (date not shown by this row’s linked mypy page).
- typing.cast() performs no runtime validation and returns its input unchanged (typing reference).
- The linked source does not confirm: the illustrative vendor.* / stubs/vendor.pyi configuration.
- No dependency name or payload schema is specified, so no concrete third-party signature can be certified.
- The r/Python strict-template report remains unattributed; it cannot establish a configuration recommendation.
- Baseline alternatives from the earlier discussion remain separate options: basedpyright baseline and Pyrefly's experimental baseline. A baseline hides existing diagnostics; it does not repair an untyped boundary.
Started from a post by @Tim Hopper, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.