首发于:https://swhl.github.io/latest/blog/vscode-use-astral-ty-type-checker/
在 12 月 1 号 时,Astral 团队发布了博客:ty 1.0,标志着 ty 这个工具初步步入成熟阶段。对于我来说,1.0 版本也是可以尝鲜使用了。
很久之前,我尝试过 mypy 工具,体验不是太好。因为项目大的时候,mypy 速度太慢了。后来就一直使用 Pylance 工具了,Pylance 内置的类型检查来自 Pyright 项目,整体体验还可以。
昨天正好看到 ty 1.0 的消息,于是就调研了一下怎么在现有 VSCode 中配置使用 ty。
经过比较发现,ty 1.0 还不能完全替代 Pylance 的全部功能,毕竟 Pylance 是微软 VSCode Python 生态的官方配套扩展。
最终,我使用的方案是 Pylance + ty 结合使用,也算是作为过渡了。
配置方法:
-
VSCode 中安装 ty 插件,目前 ty 插件已经集成了 ty 1.1.0 版本了。

-
settings.json中配置:json"python.languageServer": "Pylance", "ty.disableLanguageServices": true,
最终是 Pylance 插件 + ty 插件都安装到 VSCode 上。