Scripts2026年5月25日·1 分钟阅读

Pyre — Fast Type Checker for Python by Meta

Pyre is a performant, static type checker for Python developed at Meta, designed to catch type errors in large codebases with minimal configuration and fast incremental analysis.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Pyre Overview
通用 CLI 安装命令
npx tokrepo install 8bc4ba20-5837-11f1-9bc6-00163e2b0d79

Introduction

Pyre is a static type checker for Python that analyzes type annotations to catch bugs before runtime. Built by Meta for internal use on millions of lines of Python code, it prioritizes speed and incremental analysis so developers get fast feedback without disrupting their workflow.

What Pyre Does

  • Checks Python type annotations against PEP 484, 526, 544, and later typing PEPs
  • Runs in incremental watch mode with sub-second feedback on file saves
  • Infers return types and variable types where annotations are missing
  • Integrates with editors via the Language Server Protocol
  • Includes Pysa, a taint analysis tool for finding security vulnerabilities

Architecture Overview

Pyre is implemented in OCaml for performance. It parses Python source files into an internal AST, resolves imports and builds a module dependency graph, then runs constraint-based type inference and checking in parallel. In watch mode, it uses a file-system watcher to re-analyze only changed files and their dependents, keeping incremental checks fast even in large repos.

Self-Hosting & Configuration

  • Install via pip: pip install pyre-check
  • Initialize with pyre init to create a .pyre_configuration file
  • Set source_directories and search_path to control what gets checked
  • Use strict mode for stricter checking or unsafe to suppress specific errors
  • Configure per-file overrides with inline # pyre-strict or # pyre-ignore comments

Key Features

  • Sub-second incremental checks in watch mode for instant feedback
  • OCaml implementation delivers multi-threaded parallel analysis
  • Pysa security analyzer detects taint flows (SQL injection, XSS, etc.) using the same type infrastructure
  • LSP support provides hover types, go-to-definition, and autocomplete in editors
  • Gradual typing lets teams adopt type checking incrementally, file by file

Comparison with Similar Tools

  • mypy — The reference Python type checker; Pyre is faster on large codebases but mypy has broader community plugin support
  • Pyright — Microsoft TypeScript-based checker powering Pylance; fast and well-integrated with VS Code
  • Pytype — Google type checker with cross-function inference; slower but infers more without annotations
  • Ruff — Linter and formatter, not a type checker; complementary to Pyre

FAQ

Q: Can I use Pyre alongside mypy? A: Yes. Both read the same PEP 484 type annotations. You can run both and compare results during migration.

Q: What is Pysa? A: Pysa is Pyre's taint analysis engine that tracks untrusted data through function calls to detect security vulnerabilities like SQL injection.

Q: Does Pyre support Python 3.12+ syntax? A: Pyre tracks CPython releases. Check the changelog for the latest supported Python version.

Q: How does Pyre handle third-party libraries without type stubs? A: Pyre uses typeshed stubs and can fall back to Any for untyped libraries. You can also add custom stubs.

Sources

讨论

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

相关资产