ty

ty (pronounced tee-why) is a static type checker and language server for Python, written in Rust. Developed by Astral (creators of Ruff and uv), ty performs static analysis on Python code to identify type-related issues before runtime.

ℹ️
ty was initially known by the code name “Red-Knot” during its early development phase. The tool is currently in beta.

Key Features

  • Performance: ty is 10-100x faster than mypy and Pyright. It uses fine-grained incremental analysis to provide near-instant feedback when editing files in an IDE.
  • Comprehensive Diagnostics: Provides detailed error messages with rich contextual information, including code-span annotations that explain what went wrong.
  • Full Language Server: Ships with a complete LSP implementation including code navigation (go-to-definition, find references), completions with auto-import, rename refactoring, inlay hints, hover information, and signature help.
  • Configurable Rules: Each diagnostic rule can be set to error, warn, or ignore. Supports per-file overrides and suppression comments for fine-grained control.
  • Gradual Typing Support: Designed for adoption in existing codebases. ty avoids false positives on untyped code by using a “gradual guarantee” approach where partially typed code receives appropriate treatment.
  • Advanced Type System: Includes first-class intersection types, sophisticated type narrowing (including hasattr narrowing), and reachability analysis based on type inference.
  • Notebook Support: Provides language server features for Jupyter notebooks with cross-cell analysis.

Type System Features

ty implements several type system features beyond what other type checkers provide:

  • Redeclarations: Allows reusing the same symbol with a different type within a function scope.
  • Intersection Types: First-class support for intersection types (A & B), which enables more precise type narrowing after isinstance checks.
  • Reachability Analysis: Uses type inference to detect unreachable branches, which can handle version-specific code paths for libraries like pydantic.
  • Fixpoint Iteration: Infers types for symbols that cyclically depend on themselves by iterating until the type converges.

Installation

The quickest way to run ty is with uvx:

uvx ty check

For project use, add ty as a development dependency:

uv add --dev ty
uv run ty check

ty can also be installed globally with uv tool install ty@latest, via pip, pipx, or using standalone installers available for macOS, Linux, and Windows.

Configuration

ty reads configuration from pyproject.toml (under [tool.ty]) or a dedicated ty.toml file. Rule levels and other settings can be configured per-project:

[tool.ty.rules]
unused-ignore-comment = "warn"
possibly-missing-import = "error"

User-level configuration is also supported at ~/.config/ty/ty.toml.

Editor Integration

ty includes official editor support:

  • VS Code: Install the ty extension from the VS Code Marketplace.
  • Neovim: Configure via nvim-lspconfig or the built-in vim.lsp.config (Neovim 0.11+).
  • Zed: Built-in support (can be enabled in settings).
  • PyCharm: Native support starting with version 2025.3.

For other editors, run ty server to start the language server.

Comparison to Other Tools

ty is not a drop-in replacement for mypy or Pyright — it makes different design choices and has different default behaviors. The primary differentiators are speed (orders of magnitude faster) and the gradual typing approach that reduces false positives on untyped code. ty aims for conformance with the Python typing specification.

⚠️
ty is in beta. Some features may be missing or behave differently compared to mature type checkers. Check the tracking issue for type system feature status.

Learn More:

Last updated on

Please submit corrections and feedback...