Skip to content

Pyright: Python Static Type Checker by Microsoft

pyright is a static type checker for Python created by Microsoft that provides fast, precise type analysis, error detection, and advanced language features for large codebases. It focuses on performance, configurability, and IDE integration, powering features like autocompletion and code navigation in Visual Studio Code through the Pylance extension.

When to use pyright

Use pyright when you need a fast, reliable type checker that integrates tightly with VS Code through the Pylance extension. It is a strong choice for teams already working in VS Code who want real-time type feedback as they write code. If you primarily need a CLI type checker and already use mypy, there is no urgent reason to switch; for a comparison, see How do mypy, pyright, and ty compare?.

Core Functionality

Type Checking Engine

  • Performance-Optimized: Written in TypeScript/Node.js, faster than mypy for most workloads
  • Watch Mode: Provides real-time type checking during development
  • Incremental Analysis: Only rechecks modified files and dependencies
  • Parallel Processing: Utilizes multiple CPU cores for faster analysis
  • Memory Efficiency: Designed for large codebases with minimal overhead

Analysis Capabilities

  • Type Inference: Deduces types without explicit annotations
  • Flow Analysis: Tracks variable types through control flow paths
  • Source Mapping: Precisely maps errors to specific locations
  • Import Resolution: Correctly handles package imports and namespace packages
  • Type Stub Integration: Works with typeshed and custom stub files

Pros

  • Strong Performance: Faster than mypy on most codebases, though ty is now significantly faster than both
  • First-Class IDE Integration: Tightly integrated with VS Code via Pylance
  • Regular Updates: Frequent releases with new features and improvements
  • Corporate Backing: Maintained by Microsoft with dedicated resources
  • Granular Configuration: Highly customizable for different project needs

Cons

  • Extension Focused: Primary design for IDE integration rather than CLI use
  • TypeScript Implementation: Requires Node.js runtime

Usage Examples

# Install pyright
uv pip install pyright

# Basic type checking
pyright src/

# Specify configuration
pyright --project ./pyrightconfig.json

# Watch mode for continuous checking
pyright --watch

Learn More

Get Python tooling updates

Subscribe to the newsletter
Last updated on

Please submit corrections and feedback...