用途:ty-skills 面向 Python 类型检查,核心工具是 ty——由 Astral(uv 与 Ruff 的作者)用 Rust 编写的极快类型检查器。适用场景包括:为 Python 代码添加类型注解、修复 ty 的类型错误与诊断、配置 ty 规则与严重级别、从 mypy 或 pyright 迁移到 ty、理解高级类型模式(交叉类型、协议、泛型),以及在编辑器中设置 ty 语言服务器。
安装与基本用法:uv tool install ty,或 pip install ty。检查当前目录用 ty check;检查指定文件用 ty check src/;输出完整诊断用 ty check --output-format full。
配置:通过 pyproject.toml 配置。可在 [tool.ty.environment] 中设置 python-version、python、python-platform、root、extra-paths;在 [tool.ty.rules] 中按规则设置 error(使 CI 失败)、warn(报告)、ignore(禁用);在 [tool.ty.src] 中设置 include 与 exclude;并可用 [[tool.ty.overrides]] 对特定文件(如 tests/**)覆盖规则。
规则:资料列出部分规则及默认级别,例如 possibly-unresolved-reference、invalid-argument-type、incompatible-assignment、missing-argument、unsupported-operator、invalid-return-type 默认为 error;division-by-zero、unused-ignore-comment、redundant-cast、possibly-unbound-attribute、index-out-of-bounds 默认为 warn。
ty 独有交叉类型支持,可用 reveal_type 显示如 Serializable & Versioned 的类型。抑制注释支持单规则与多规则形式,如 # type: ignore[incompatible-assignment]。
参考文档:references/ty_rules_reference.md、typing_cheatsheet.md、advanced_patterns.md、migration_guide.md、common_errors.md 及 editor_setup/(VS Code、Cursor、Neovim)。资源包括 ty 文档、Playground 与 GitHub。具体版本要求、平台支持与收费信息暂未提供。