Skip to content

Coming from mypy or pyright

This guide helps you migrate a project from mypy or pyright to ty.

Migration tips

  • mypy disables an error code with # 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.
  • mypy's disable_error_code and pyright's reportXyz = "none" both correspond to setting <rule> = "ignore" under [tool.ty.rules]. See this section for details.
  • Severities in ty are ignore, warn, error. Pyright's "information" and "hint" levels have no direct ty equivalent — use warn for both.
  • If you are looking for the equivalent of disallow_untyped_defs / no-untyped-def (mypy) or reportMissingParameterType, reportUnknownParameterType (pyright), check out this FAQ entry.
  • Unlike mypy, ty checks the bodies of unannotated functions unconditionally, so there is no ty rule corresponding to mypy's check_untyped_defs setting. The equivalent pyright setting is analyzeUnannotatedFunctions = true.

Stricter checking with ty

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.rules]
missing-type-argument = "error"
possibly-unresolved-reference = "warn"

[tool.ruff.lint]
extend-select = ["ANN", "PYI"]
preview = true

This configuration:

  • Ensures ty exits with a non-zero status if it emits any warning-level diagnostics
  • Enables ty's disabled-by-default missing-type-argument and possibly-unresolved-reference rules
  • Extends Ruff's default rules with the ANN and PYI rule categories, both of which are focussed on type-annotating your code more effectively
  • Enables Ruff's preview mode so that PYI033 also checks .py files

Note that several checks in mypy and pyright are not yet implemented in ty. See the rule mapping table below for more details.

Mapping pyright/mypy rules to ty/Ruff rules

How to read this table

  • ty or Ruff rule: the canonical name, as listed in Rules if it is a ty rule. Configure ty rules under [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.
  • mypy error code: the value passed to # 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.
  • pyright diagnostic: the 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).

Rules

ty or Ruff rule mypy error code pyright diagnostic
call-abstract-method reportAbstractUsage
call-non-callable operator reportCallIssue
conflicting-declarations no-redef reportRedeclaration
conflicting-metaclass metaclass reportGeneralTypeIssues
cyclic-class-definition misc reportGeneralTypeIssues
deprecated deprecated reportDeprecated
division-by-zero
duplicate-base misc reportGeneralTypeIssues
empty-body empty-body
inconsistent-mro misc reportGeneralTypeIssues
index-out-of-bounds misc reportGeneralTypeIssues
invalid-argument-type arg-type
index
type-var
typeddict-item
reportArgumentType
reportAssignmentType
invalid-assignment assignment reportAssignmentType
invalid-attribute-access misc reportAttributeAccessIssue
invalid-await misc reportGeneralTypeIssues
invalid-base valid-type reportGeneralTypeIssues
invalid-context-manager misc
attr-defined
reportGeneralTypeIssues
invalid-exception-caught misc reportGeneralTypeIssues
invalid-key typeddict-item
typeddict-unknown-key
reportAssignmentType
invalid-metaclass metaclass
invalid-method-override override reportIncompatibleMethodOverride
invalid-overload no-overload-impl reportNoOverloadImplementation
invalid-parameter-default assignment reportArgumentType
invalid-raise misc reportGeneralTypeIssues
invalid-return-type return-value reportReturnType
invalid-type-arguments misc
type-var
reportInvalidTypeArguments
invalid-type-form valid-type reportInvalidTypeForm
missing-argument call-arg reportCallIssue
missing-override-decorator explicit-override reportImplicitOverride
missing-type-argument type-arg reportMissingTypeArgument
missing-typed-dict-key typeddict-item reportAssignmentType
no-matching-overload call-overload reportCallIssue
not-iterable misc
attr-defined
reportGeneralTypeIssues
not-subscriptable index reportIndexIssue
parameter-already-assigned misc
call-arg
reportCallIssue
possibly-missing-attribute
possibly-unresolved-reference possibly-undefined reportPossiblyUnboundVariable
redundant-cast redundant-cast reportUnnecessaryCast
too-many-positional-arguments call-arg reportCallIssue
type-assertion-failure assert-type reportAssertTypeFailure
undefined-reveal unimported-reveal
unknown-argument call-arg reportCallIssue
unresolved-attribute attr-defined
union-attr
reportAttributeAccessIssue
reportOptionalMemberAccess
unresolved-import import-not-found reportMissingImports
unresolved-reference name-defined reportUndefinedVariable
unsupported-operator operator reportOperatorIssue
unused-awaitable unused-coroutine
unused-awaitable
reportUnusedCoroutine
unused-ignore-comment unused-ignore reportUnnecessaryTypeIgnoreComment
None yet (tracked in Ruff #10137) reportConstantRedefinition
Ruff F811
Ruff I001
reportDuplicateImport
None yet (tracked in #3647) reportImportCycles
None yet reportIncompleteStub
None yet (tracked in #3651) reportInconsistentConstructor
Ruff W605 reportInvalidStringEscapeSequence
Ruff PYI010
Ruff PYI017
Ruff PYI048
Ruff PYI052
reportInvalidStubStatement
None yet (tracked in #1017, #3636, #3637) type-var reportInvalidTypeVarUse
None yet (tracked in #1060) exhaustive-match reportMatchNotExhaustive
None yet (tracked in #1577) reportMissingModuleSource
None yet (tracked in #3652) reportMissingSuperCall
None yet (tracked in #3638) import-untyped reportMissingTypeStubs
None yet (tracked in #103) overload-overlap reportOverlappingOverload
None yet (tracked in #200) attr-defined
(extended by --no-implicit-reexport)
reportPrivateImportUsage
None yet (tracked in #3633) reportPropertyTypeMismatch
Ruff N804
Ruff N805
reportSelfClsParameterName
Ruff PYI033 (preview only) reportTypeCommentUsage
None yet (tracked in #2810) reportTypedDictNotRequiredAccess
None yet (tracked in #2954) reportUninitializedInstanceVariable
None yet (tracked in #576) comparison-overlap reportUnnecessaryComparison
reportUnnecessaryContains
None yet (tracked in #1948) unreachable reportUnreachable
Ruff F822
Ruff PLE0604
Ruff PLE0605
Ruff PYI056
reportUnsupportedDunderAll
Ruff PYI024 reportUntypedNamedTuple
Ruff B018 reportUnusedExpression
Ruff F403 reportWildcardImportFromLibrary
None yet no-any-return
None yet no-untyped-call
Ruff ANN rules no-untyped-def reportMissingParameterType
reportUnknownParameterType
None yet untyped-decorator reportUntypedFunctionDecorator

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.