Back to Ty

Coming from mypy or pyright

docs/coming-from-mypy-or-pyright.md

0.0.459.6 KB
Original Source

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.

How to read this table

  • ty rule: the canonical name, as listed in Rules. Configure under [tool.ty.rules].
  • 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).

Mapping table

ty rulemypy error codepyright diagnostic
call-abstract-methodreportAbstractUsage
call-non-callableoperatorreportCallIssue
conflicting-declarationsno-redefreportRedeclaration
conflicting-metaclassmetaclassreportGeneralTypeIssues
cyclic-class-definitionmiscreportGeneralTypeIssues
deprecateddeprecatedreportDeprecated
division-by-zero
duplicate-basemiscreportGeneralTypeIssues
empty-bodyempty-body
inconsistent-mromiscreportGeneralTypeIssues
index-out-of-boundsmiscreportGeneralTypeIssues
invalid-argument-typearg-type
index
type-var
typeddict-itemreportArgumentType
reportAssignmentType
invalid-assignmentassignmentreportAssignmentType
invalid-attribute-accessmiscreportAttributeAccessIssue
invalid-awaitmiscreportGeneralTypeIssues
invalid-basevalid-typereportGeneralTypeIssues
invalid-context-managermisc
attr-definedreportGeneralTypeIssues
invalid-exception-caughtmiscreportGeneralTypeIssues
invalid-keytypeddict-item
typeddict-unknown-keyreportAssignmentType
invalid-metaclassmetaclass
invalid-method-overrideoverridereportIncompatibleMethodOverride
invalid-overloadno-overload-implreportNoOverloadImplementation
invalid-parameter-defaultassignmentreportArgumentType
invalid-raisemiscreportGeneralTypeIssues
invalid-return-typereturn-valuereportReturnType
invalid-type-argumentsmisc
type-varreportInvalidTypeArguments
invalid-type-formvalid-typereportInvalidTypeForm
missing-argumentcall-argreportCallIssue
missing-override-decoratorexplicit-overridereportImplicitOverride
missing-typed-dict-keytypeddict-itemreportAssignmentType
no-matching-overloadcall-overloadreportCallIssue
not-iterablemisc
attr-definedreportGeneralTypeIssues
not-subscriptableindexreportIndexIssue
parameter-already-assignedmisc
call-argreportCallIssue
possibly-missing-attributeunion-attrreportOptionalMemberAccess
reportAttributeAccessIssue
possibly-unresolved-referencepossibly-undefinedreportPossiblyUnboundVariable
redundant-castredundant-castreportUnnecessaryCast
too-many-positional-argumentscall-argreportCallIssue
type-assertion-failureassert-typereportAssertTypeFailure
undefined-revealunimported-reveal
unknown-argumentcall-argreportCallIssue
unresolved-attributeattr-definedreportAttributeAccessIssue
unresolved-importimport-not-foundreportMissingImports
unresolved-referencename-definedreportUndefinedVariable
unsupported-operatoroperatorreportOperatorIssue
unused-awaitableunused-coroutine
unused-awaitablereportUnusedCoroutine
unused-ignore-commentunused-ignorereportUnnecessaryTypeIgnoreComment

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.