Python类型查询新协议替代LSP
推荐指数 68.0 NO. 014 · 2026.10.27
发布2026/10/26Score158Comments117
简介
TSP是专为Python类型分析设计的JSON-RPC协议,让IDE直接查询类型服务器获取计算类型、声明类型和预期类型。对AI工程师来说,这意味着构建Python代码分析工具时不必强行套用LSP,类型推断的准确性和响应速度可能大幅提升。
编辑判断
Python的类型推断一直是IDE体验的短板,Pyright和Pylance虽然基于LSP,但类型查询和语言功能混杂在一起,导致大项目里补全延迟明显。TSP把类型分析拆成独立服务,思路类似Rust的rust-analyzer把HIR查询单独暴露的做法。
目前微软还没官方背书TSP,但代码仓库在microsoft组织下,很可能是Pylance下一代架构的试验。如果你在维护Python静态分析工具或AI代码助手,现在可以抢先实现tsp.json的客户端,比等官方文档齐全再动手能抢一到两个季度的时间窗口。
一个直接的应用场景:AI编程助手做上下文收集时,常常需要快速拿到光标处变量的精确类型来检索相关定义,TSP的类型查询比完整LSP请求轻量得多,延迟能从百毫秒级降到十毫秒级。
社区反馈
意见分歧 91 条评论
核心争论:TSP 命名是否抢占通用协议空间,以及 Python 专属协议能否/应否推广到其他语言
This should be called Python Type Server Protocol, no? Seems weird to mine the generic protocol namespace for a protocol that only supports Python. Especially coming from the company behind LSP, which actually is generic.
It is namespaced under the pylance project. I also don't see any announcement here, just a markdown file. Perhaps the post title could use a tweak
This was the announcement https://devblogs.microsoft.com/python/announcing-tsp/