Skills2026年4月30日·1 分钟阅读

Pyright — Fast Static Type Checker for Python

Pyright is a high-performance Python type checker written in TypeScript that provides real-time type analysis, type inference, and IDE integration.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Pyright Overview
直接安装命令
npx -y tokrepo@latest install be729969-442b-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Pyright is a static type checker for Python created by Microsoft. Written in TypeScript and running on Node.js, it delivers significantly faster analysis than traditional Python-based type checkers, making it practical for large codebases with millions of lines.

What Pyright Does

  • Performs full static type analysis of Python code using PEP 484 type annotations
  • Infers types for unannotated code using flow-sensitive narrowing and control flow analysis
  • Reports type errors, missing imports, and unreachable code at development time
  • Powers the Pylance VS Code extension for real-time editor diagnostics
  • Supports all typing constructs including generics, protocols, TypedDict, and ParamSpec

Architecture Overview

Pyright parses Python source files into an AST, then runs multiple analysis passes: import resolution, scope analysis, type evaluation, and type narrowing. Its incremental architecture re-analyzes only changed files and their dependents. Because it runs on Node.js rather than CPython, startup and throughput are substantially faster than mypy for equivalent codebases.

Self-Hosting & Configuration

  • Install via pip (pip install pyright) or npm (npm install pyright)
  • Configure through a pyrightconfig.json file at the project root
  • Set typeCheckingMode to basic, standard, or strict for varying rigor levels
  • Define include and exclude paths to control which files are analyzed
  • Use venvPath and venv settings to point Pyright at virtual environments

Key Features

  • Analyzes large codebases 3-5x faster than mypy due to TypeScript runtime
  • Watch mode re-checks only affected files on save for near-instant feedback
  • Supports PEP 695 type parameter syntax and all modern typing features
  • Provides detailed diagnostic messages with fix suggestions
  • Full Language Server Protocol support for IDE integration beyond VS Code

Comparison with Similar Tools

  • mypy — the original Python type checker, slower but with a broader plugin ecosystem
  • pytype — Google's type checker with automatic type inference and rewriting
  • Pyre — Meta's type checker focused on large monorepos with incremental analysis
  • Ruff — ultrafast linter and formatter but does not perform type checking
  • Pylint — general-purpose linter that catches code smells but not type errors

FAQ

Q: Can I use Pyright alongside mypy? A: Yes. Many teams run both in CI. Pyright and mypy may flag different issues due to differing inference strategies, so overlapping coverage can catch more bugs.

Q: Does Pyright replace Pylance? A: Pylance is a VS Code extension that bundles Pyright as its type-checking engine and adds IDE features like auto-imports and semantic highlighting. Pyright is the standalone CLI.

Q: How do I migrate a project from mypy to Pyright? A: Replace the mypy config with a pyrightconfig.json, run Pyright, and address any new diagnostics. Most PEP 484 annotations are fully compatible between the two.

Q: Does Pyright work with Django and other dynamic frameworks? A: Pyright handles most Django patterns when paired with django-stubs type stubs. Highly dynamic code may need targeted # type: ignore annotations.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产