ワンクリックで
migrate-from-mypy-to-ty
Migrate Python repositories from mypy to ty for static type checking.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Migrate Python repositories from mypy to ty for static type checking.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Validate Python code blocks in Markdown documentation using pytest-codeblock.
Bootstrap repository governance by creating AGENTS.md and a standard set of SKILL.md files.
Create and modify repository-specific SKILL.md policy files in strict compliance with AGENTS.md and existing project skills.
Migrate Python repositories from virtualenv, virtualenvwrapper, pip-tools, requirements files, setup.py, or setup.cfg to a uv-managed pyproject.toml and uv.lock workflow.
Keep project documentation aligned with code by detecting and auto-fixing mismatches using agent-based analysis.
| name | migrate-from-mypy-to-ty |
| description | Migrate Python repositories from mypy to ty for static type checking. |
This skill replaces mypy with ty as the static type checker across all
project surfaces: dependencies, configuration, Makefile targets, pre-commit
hooks, CI pipelines, and documentation.
ty is the Astral type checker (uv add --group dev ty).
The canonical invocation in a uv-managed project is uv run ty check.
This skill applies to all surfaces where mypy is referenced:
pyproject.toml — dependency groups and [tool.mypy] configurationMakefile — mypy targets and phony declarations.pre-commit-config.yaml — mypy hooks.github/workflows/, tox.ini, etc.)This skill MUST NOT modify:
If the migrate-to-uv skill was previously applied, the following artifacts
reference mypy and MUST be updated by this skill:
uv run mypy {{ mypy_paths }} → uv run ty checkmake mypy → make ty (or equivalent)pyproject.toml template: [tool.mypy] → [tool.ty]Before making any change, identify all mypy references:
pyproject.toml: mypy in [dependency-groups] or
[project.optional-dependencies]; [tool.mypy] sectionMakefile: targets, .PHONY, variables, and help output mentioning mypy.pre-commit-config.yaml: any hook with mypy in id, name, or repomypyREADME.*, docs/: command examples referencing mypytox.ini or tox.toml: any mypy commands in [testenv] sectionsRecord every file and line before editing. The survey output drives the migration; do not skip files that appear to be low-risk.
MUST remove mypy and all mypy plugins from every dependency group:
uv remove mypy
uv remove mypy-extensions
uv remove types-* # remove all stub packages added for mypy
MUST add ty:
uv add --group dev ty
Rules:
ty goes in the dev dependency group unless the project uses a dedicated
lint or typecheck group, in which case it goes there.types-requests, types-PyYAML, etc.) MUST be
evaluated individually — ty bundles many stubs; remove only those no longer
needed.ty as a runtime ([project].dependencies) dependency.Remove the [tool.mypy] section and any [[tool.mypy.overrides]] sections
from pyproject.toml in their entirety.
MUST NOT leave a [tool.mypy] section with no entries as a "placeholder."
Add a minimal [tool.ty.environment] section. Encode only settings that are
explicitly required by the project:
[tool.ty.environment]
# Required when the package lives under src/ — tells ty where to resolve imports
root = ["src"]
For multi-root projects (examples, benchmarks, etc.) list every directory that must be importable:
[tool.ty.environment]
root = ["src", "benchmarks", "examples/gae"]
Valid top-level keys under [tool.ty] are: environment, src, rules,
terminal, analysis, overrides. Attempting to add any other key (e.g.
exclude) causes a hard TOML parse error.
Rules:
disallow_untyped_defs, etc.) MUST NOT be
blindly copied; verify whether ty supports the equivalent before adding it.ty does not support a mypy flag that the project relied on, document the
gap in a comment and raise it in the completion report rather than silently
dropping it.# type: ignore (PEP 484 / mypy syntax) is a silent no-op in ty. ty uses
its own syntax:
some_expression # ty: ignore[rule-name]
The rule name matches exactly what ty prints in brackets, e.g.
error[unresolved-reference] → # ty: ignore[unresolved-reference].
Running uv run ty check --add-ignore inserts # ty: ignore comments
automatically for every current diagnostic — useful as a starting point.
MUST audit every existing # type: ignore comment in the codebase:
uv run ty check and note which locations ty flags.# type: ignore location:
# type: ignore[...] with
# ty: ignore[rule-name].# type: ignore comments as migration artefacts — they provide
no suppression and create false confidence.ty checks .ipynb files by default when it scans the project root. Projects
with Jupyter notebooks may receive unexpected unresolved-attribute errors
because notebook cells call methods on union return types without type narrowing.
For each failing notebook cell that accesses attributes on a typed result:
assert isinstance(res, ExpectedType) in the cell
where the variable is assigned. ty narrows the type for all subsequent cells.# ty: ignore[unresolved-attribute] to the specific
line inside the cell source.Do not attempt to suppress notebook errors via exclude under [tool.ty] —
that key is not valid there and will cause a parse error.
Patterns that ty catches which mypy often accepted silently:
| Pattern | ty error code | Fix |
|---|---|---|
mod.attr = val on a types.ModuleType | unresolved-attribute | Use setattr(mod, "attr", val) or # ty: ignore[unresolved-attribute] |
Referencing a runtime-injected global (e.g. kernprof's profile) | unresolved-reference | Use # ty: ignore[unresolved-reference] |
Calling a method that doesn't exist on the actual type (e.g. .close() on list, hidden by contextlib.suppress) | unresolved-attribute | Remove the dead call |
Accessing attributes on a union type without narrowing (e.g. Optional[Union[str, Result]]) | unresolved-attribute | Add assert isinstance(...) or cast before attribute access |
MUST replace every mypy-related target:
mypy: → ty: (or typecheck:)uv run mypy $(MYPY_PATHS) → uv run ty check.PHONY to reference the new target namehelp output if the project uses a help targetMYPY_PATHS) if it is no longer neededMUST NOT leave a dead mypy: target alongside a new ty: target.
Inspect .pre-commit-config.yaml for any mypy hook:
https://github.com/pre-commit/mirrors-mypy is present,
remove the entire repo block.mypy appears as a local hook, replace the command with ty check.ty does not yet have a pre-commit mirror available, use a local hook:- repo: local
hooks:
- id: ty
name: ty
entry: uv run ty check
language: system
types: [python]
pass_filenames: false
Critical — extras and import resolution: uv run ty check creates a fresh
.venv containing only the project's base (non-optional) dependencies. ty uses
that environment for import resolution. If any source files import packages that
live in optional dependency groups (e.g. pytest in test, ty itself
in lint), ty will emit unresolved-import errors for those modules even
though they are installed elsewhere.
Fix: pass --extra <group> for every optional group whose packages appear in
source files that ty analyses:
entry: uv run --extra lint --extra test ty check
Include every group whose imports appear in files scanned by ty — typically
test (for pytest, test helpers) and lint (for ty itself if it is not a
base dependency). The --extra flags cause uv to install those groups into the
managed .venv before ty runs.
Run uv run pre-commit run --all-files after updating the file.
In every CI pipeline file, replace:
mypy install steps with ty (usually handled by uv sync)mypy or uv run mypy commands with uv run ty check.mypy_cache) with the ty
equivalent (.ty_cache) if caching is enabledUpdate all documentation referencing mypy:
docs/ pages with type checking instructionsmypy explicitly (e.g. verification
sequences in migrate-to-uv or dev-workflow)MUST NOT leave user-facing documentation that instructs users to run mypy
after this migration is complete.
If any code examples in Markdown reference mypy, they MUST be updated to
reference ty. Code examples in Markdown MUST comply with the
doc-codeblock-tests skill (Python code blocks must be named test_*).
MUST run these checks in order after completing all changes:
uv lock
uv sync --all-groups --all-extras
uv run ty check
uv run pre-commit run --all-files
If a Makefile target was created:
make ty # or make typecheck — match the new target name
A migration is NOT complete until uv run ty check exits zero.
mypy in any dependency group after migration[tool.mypy] in pyproject.toml after migration# type: ignore comments in the codebase after migration —
ty does not honour them; they suppress nothing and create false confidence.
Convert to # ty: ignore[rule-name] where ty still flags the location, or
remove them where ty does not.Report after migration: