docs/coming-from-mypy-or-pyright.md
This guide helps you migrate a project from mypy or pyright to ty.
# type: ignore[code]; pyright suppresses a single line with
# pyright: ignore[reportXyz]; ty's equivalent is # ty: ignore[rule].
See this page for more information about suppression comments.disable_error_code and pyright's reportXyz = "none" both correspond to setting
<rule> = "ignore" under [tool.ty.rules]. See this section for
details.ignore, warn, error. Pyright's "information" and "hint" levels have
no direct ty equivalent — use warn for both.disallow_untyped_defs / no-untyped-def (mypy) or reportMissingParameterType,
reportUnknownParameterType (pyright), check out this
FAQ entry.check_untyped_defs setting. The equivalent pyright setting is
analyzeUnannotatedFunctions = true.For both mypy and pyright, "strict" mode enables several error codes that are otherwise disabled by
default, but also makes fundamental changes to the way type inference and type checking works.
Mypy's strict mode includes --check-untyped-defs, for example, without which unannotated
functions are left unchecked; pyright's strict mode includes strictListInference, without which
[1, "foo"] will be inferred as having type list[Unknown] rather than list[int | str] or
similar.
ty's default mode is currently stricter by default than either mypy or pyright in many ways. ty
does not have flags such as --check-untyped-defs or strictListInference, because these are
ty's default behaviour and are not currently configurable. Meanwhile, nearly all ty rules are
enabled by default, and the ones that are disabled by default are usually in that category because
they are either very opinionated or have many false positives.
To enable all ty rules at once with the error severity, you can simply use --error=all, but we
wouldn't recommend it. Instead, you can currently approximate something similar to the --strict
mode of other type checkers with the following configuration:
[tool.ty.terminal]
error-on-warning = true
[tool.ty.rules]
missing-type-argument = "error"
possibly-unresolved-reference = "warn"
[tool.ruff.lint]
extend-select = ["ANN", "PYI"]
This configuration:
missing-type-argument and possibly-unresolved-reference rulesANN and PYI rule categories, both of which are focussed on type-annotating your code more effectivelyNote that several checks in mypy and pyright are not yet implemented in ty. See the rule mapping table below for more details.
[tool.ty.rules]. Where Ruff provides equivalent coverage for a
check that has no ty rule, the relevant Ruff rule or rule group is linked instead.# type: ignore[<code>] or disable_error_code. Some ty
rules surface as one of mypy's catch-all codes (misc, assignment, valid-type); these
mappings are deliberately broad.report* setting in pyrightconfig.json or [tool.pyright].A blank cell means no direct equivalent exists in that checker (the diagnostic is either not emitted, or is folded into a broader category that already appears for another ty rule).
The full list of ty rules — including those without a direct equivalent above — is in
Rules. Contributions to extend this mapping are welcome via pull request to the
ty repository; see issue
#2111 for context.