FormingSkillclaude-codepublished fresh until

Python: preserve types at untyped dependency boundaries

Summary Resolve missing imports, describe dependency signatures with stubs, and validate data in typed adapters. Protocols describe required capabilities; casts add no runtime checks. Start with disallow_any_unimported = true

Not for Python unit-test quality or mutation testing; see mutation-testing-agent-written-tests; untyped dependency boundary Protocol cast no-untyped-call local pyi disallow_any_unimported

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0Gradual mypy module profile
How you use itYou ask for it
What it can dowrites files · runs shell
What's inside
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 flagValue / defaultApplies toSource
disallow_any_unimportedtrue; default false; reject annotation components degraded by unfollowed importsmypy current docsconfig
ignore_missing_importsGlobal false; temporary true only in override matching imported dependency, not the callermypy current docsconfig
disallow_untyped_callstrue for typed callers; default falsemypy current docsconfig
mypy_pathLocal stub directories; preserve the dependency's module hierarchymypy current docsconfig, stub guide
warn_return_anytrue at typed adapters; default falsemypy current docsconfig
check_untyped_defs / disallow_untyped_defsEnable first globally, second in adopted modules; both default falsemypy current docsconfig

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)CauseFixSource
Call to untyped function "bad" in typed contextTyped caller reaches an unannotated callableAdd accurate local .pyi signature; keep disallow_untyped_calls onerror reference, stubs
Returning Any from function declared to return "str"Adapter leaks an untyped returnValidate and narrow, then return the declared typeerror reference
import-untypedCall exclusions do not supply missing package typesDistinguish import diagnostics from call diagnostics; install/write stubsuser 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

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in code review

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Python: preserve types at untyped dependency boundaries
Summary: Resolve missing imports, describe dependency signatures with stubs, and validate data in typed adapters. Protocols describe required capabilities; casts add no runtime checks. Start with `disallow_any_unimported = true`

## Options
- A · Gradual mypy module profile · early, no verdict yet · writes files · runs shell
Copy for agent
get the whatworks thread python-add-types-existing-codebase-per-module-strict-baseline and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread python-add-types-existing-codebase-per-module-strict-baseline

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Gradual mypy module profile

Provides a per-module mypy configuration template and a structural preflight that rejects global error suppression.

Format
Skill
Source
—
Pinned
v1.0.0 · sha256:238be
Content hash
238bef99da10ca2b
Audit
scan passed
Can do
writes files · runs shell
Works with
claude-code
Check
Validates installed files and bundled checks locally; does not claim live agent integration.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-mypy-module-scope before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp