一句话:提出静态类型推荐方法 Stray,为 Python 代码正确推荐类型注解,精度与召回率显著优于机器学习基线。
Python 支持可选类型注解以进行类型检查与程序文档说明,但开发者手工编写注解十分耗时。已有基于机器学习的类型推荐方法依赖代码特征,却存在推荐类型无法通过类型检查的正确性问题。本文提出静态类型推荐方法 Stray,能够正确推荐类型,从而缓解上述正确性问题。作者将 Stray 与四种当前先进的类型推荐方法进行比较,实验发现 Stray 在精度和召回率上均取得超过 30% 的绝对提升。
Recently, Python has adopted optional type annotation to support type checking and program documentation. However, to enjoy the benefits, developers have to manually write type annotations, which is recognized to be a time-consuming task. To alleviate human efforts on manual type annotation, machine-learning-based approaches have been proposed to recommend types based on code features. However, they suffer from the correctness problem, i.e., the recommended types cannot pass type checking. To address the correctness problem of the machine-learning-based approaches, in this paper, we present a static type recommendation approach, named Stray. Stray can recommend types correctly. We evaluate Stray by comparing it against four state-of-art type recommendation approaches, and find that Stray outperforms these baselines by over 30% absolute improvement in both precision and recall.