Migrate from mypy to ty
Skill barseghyanartur/dot-agents/skills/migrate-from-mypy-to-ty
A collection of agent-operable skills for repository governance, development workflows, and Python project management.
npx -y skills add barseghyanartur/dot-agents --skill migrate-from-mypy-to-tyAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Migrate Python repositories from mypy to ty for static type checking.
SKILL.md
10.6 KB, as published. Nobody here has run it
Migrate from mypy to ty (AUTHORITATIVE)
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.
Scope
This skill applies to all surfaces where mypy is referenced:
pyproject.toml— dependency groups and[tool.mypy]configurationMakefile—mypytargets and phony declarations.pre-commit-config.yaml— mypy hooks- CI pipeline files (
.github/workflows/,tox.ini, etc.) - Documentation and README files
This skill MUST NOT modify:
- Source code type annotations
- Any file outside the surfaces listed above
Relationship with migrate-to-uv
If the migrate-to-uv skill was previously applied, the following artifacts
reference mypy and MUST be updated by this skill:
- Verification commands:
uv run mypy {{ mypy_paths }}→uv run ty check - Makefile targets:
make mypy→make ty(or equivalent) pyproject.tomltemplate:[tool.mypy]→[tool.ty]
Phase 1 — Survey (READ-ONLY)
Before making any change, identify all mypy references:
pyproject.toml:mypyin[dependency-groups]or[project.optional-dependencies];[tool.mypy]sectionMakefile: targets,.PHONY, variables, andhelpoutput mentioningmypy.pre-commit-config.yaml: any hook withmypyinid,name, orrepo- CI files: steps or commands referencing
mypy README.*,docs/: command examples referencingmypytox.iniortox.toml: anymypycommands in[testenv]sections
Record every file and line before editing. The survey output drives the migration; do not skip files that appear to be low-risk.
Phase 2 — Dependency migration
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:
tygoes in thedevdependency group unless the project uses a dedicatedlintortypecheckgroup, in which case it goes there.- Third-party stub packages (
types-requests,types-PyYAML, etc.) MUST be evaluated individually —tybundles many stubs; remove only those no longer needed. - Do not add
tyas a runtime ([project].dependencies) dependency.
Phase 3 — Configuration migration
Remove mypy configuration
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 ty configuration
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:
- Do not mechanically translate every mypy flag to a ty equivalent; ty has different defaults and a different flag surface.
- Strictness settings from mypy (
disallow_untyped_defs, etc.) MUST NOT be blindly copied; verify whether ty supports the equivalent before adding it. - If
tydoes 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.
Ignore comment migration
# 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:
- Run
uv run ty checkand note which locations ty flags. - For each
# type: ignorelocation:- If ty still flags it → replace
# type: ignore[...]with# ty: ignore[rule-name]. - If ty does not flag it → remove the comment (it is dead).
- If ty still flags it → replace
- Do not leave
# type: ignorecomments as migration artefacts — they provide no suppression and create false confidence.
Jupyter notebook awareness
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:
- Preferred fix: add
assert isinstance(res, ExpectedType)in the cell where the variable is assigned. ty narrows the type for all subsequent cells. - Alternative: add
# 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.
Common ty error patterns
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 |
Phase 4 — Makefile migration
MUST replace every mypy-related target:
- Rename the target:
mypy:→ty:(ortypecheck:) - Replace the command:
uv run mypy $(MYPY_PATHS)→uv run ty check - Update
.PHONYto reference the new target name - Update the
helpoutput if the project uses a help target - Remove or rename any variable that was dedicated to mypy paths (e.g.
MYPY_PATHS) if it is no longer needed
MUST NOT leave a dead mypy: target alongside a new ty: target.
Phase 5 — Pre-commit migration
Inspect .pre-commit-config.yaml for any mypy hook:
- If a mypy hook from
https://github.com/pre-commit/mirrors-mypyis present, remove the entire repo block. - If
mypyappears as a local hook, replace the command withty check. - If
tydoes 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.
Phase 6 — CI migration
In every CI pipeline file, replace:
mypyinstall steps withty(usually handled byuv sync)mypyoruv run mypycommands withuv run ty check- Any caching configuration keyed on mypy (
.mypy_cache) with the ty equivalent (.ty_cache) if caching is enabled
Phase 7 — Documentation migration
Update all documentation referencing mypy:
- README setup or usage instructions
- Developer guides
docs/pages with type checking instructions- AGENTS.md or SKILL.md files that name
mypyexplicitly (e.g. verification sequences inmigrate-to-uvordev-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_*).
Phase 8 — Verification
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.
Prohibited practices
- MUST NOT leave
mypyin any dependency group after migration - MUST NOT leave
[tool.mypy]inpyproject.tomlafter migration - MUST NOT blindly copy mypy configuration flags that ty does not support
- MUST NOT silently drop type errors that mypy caught but ty does not yet catch — document any known regressions in the completion report
- MUST NOT leave
# type: ignorecomments 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.
Completion report (MANDATORY)
Report after migration:
- All files modified and the nature of each change
- Mypy flags that were dropped because ty does not support them
- Third-party stub packages removed and any retained with justification
- Known type errors suppressed by ty that mypy would have flagged
- Any surfaces left unmodified (e.g. tox skipped because the project uses it for legacy CI only) with explicit justification