一句话:提出 QuAC,通过收集 Python 表达式访问的属性集合并用信息检索预测类,实现快速准确的类型推断。
Python 的动态类型利于快速开发,却削弱静态检查与缺陷检测工具。类型标注能提升工具效果,但人工添加负担大;现有类型推断难以兼顾动态特性、容器参数与非内置类型,且耗时较长。受鸭子类型启发,QuAC 收集 Python 表达式访问的属性集合,将其视为隐式接口,并用信息检索预测类,同时递归预测容器类型参数。在流行 Python 项目上,QuAC 相比先进非 LLM 基线在不损失覆盖率下取得互补高准确率,在容器参数与非内置类型上优势明显且更快;相比 LLM 方法,它快近两个数量级,并覆盖其近半数无错误非平凡预测。
Python’s dynamic typing facilitates rapid prototyping and underlies its popularity in many domains. However, dynamic typing reduces the power of many static checking and bug-finding tools. Python type annotations can make these tools more useful. Type inference tools aim to reduce developers’ burden of adding them. However, existing type inference tools struggle to support dynamic features, infer correct types (especially container type parameters and non-builtin types), and run in reasonable time. Inspired by Python’s duck typing, where the attributes accessed on Python expressions characterize their implicit interfaces, we propose QuAC (Quick Attribute-Centric Type Inference for Python). At its core, QuAC collects attribute sets for Python expressions and leverages information retrieval techniques to predict classes from these attribute sets. It also recursively predicts container type parameters. We evaluate QuAC’s performance on popular Python projects. Compared to state-of-the-art non-LLM baselines, QuAC predicts types with high accuracy complementary to those predicted by the baselines while not sacrificing coverage. It also demonstrates clear advantages in predicting container type parameters and non-builtin types and reduces run times. Furthermore, QuAC is nearly two orders of magnitude faster than an LLM-based method while covering nearly half of its errorless non-trivial type predictions. It is also significantly more consistent at predicting container type parameters and non-builtin types than the LLM-based method, regardless of whether the project has ground-truth type annotations.
@article{WuL24,
title = {QuAC: Quick Attribute-Centric Type Inference for Python},
author = {Jifeng Wu and Caroline Lemieux},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {OOPSLA2},
year = {2024},
doi = {10.1145/3689783}
}