Typify:一种轻量级的基于使用驱动的静态分析器用于精确的Python类型推断
Typify: A Lightweight Usage-driven Static Analyzer for Precise Python Type Inference
AI总结:
本文提出Typify,一种轻量级静态分析器,通过符号执行和迭代固定点分析推断Python代码中的类型信息,无需依赖统计学习或大数据集,有效提升类型推断的准确性和可解释性。
摘要:
Python的动态类型系统虽然提供了显著的灵活性和表达性,但对静态分析和自动化工具提出了重大挑战,尤其是在无注释或部分注释的代码库中。现有的类型推断方法通常依赖于现有的类型注解或深度学习模型,这些模型需要大量的训练语料和计算资源,导致可扩展性和可解释性受限。我们引入Typify,一种轻量级、基于使用驱动的静态分析引擎,旨在推断精确且上下文相关的类型信息,而无需依赖统计学习或大数据集。Typify集成了符号执行与迭代固定点分析以及上下文匹配检索系统,以在整个项目中传播和预测类型信息。通过构建和遍历执行感知的依赖图,Typify能够准确地将函数调用连接到其定义,并推断基于使用类型的语义,即使在复杂的、相互依赖的模块中。我们对多种真实的Python仓库进行了评估,包括ManyTypes4Py和Typilus数据集,测试其在预测变量、参数和返回语句类型的有效性。评估结果表明,Typify在预测变量、参数和返回语句类型的准确性上与最先进的深度学习系统如Type4Py和HiTyper以及行业标准的静态类型推断工具如Pyre相当或更优。我们的发现表明,基于使用驱动的检索推断可以与数据驱动方法相媲美,为大型和不断演化的Python代码库提供了一个实用、可解释且计算效率高的替代方案。
英文摘要:
Python's dynamic type system, while offering significant flexibility and expressiveness, poses substantial challenges for static analysis and automated tooling, particularly in unannotated or partially annotated codebases. Existing type inference approaches often depend on existing type annotations or on deep learning models that require extensive training corpora and considerable computational resources, resulting in limited scalability and reduced interpretability. We introduce Typify, a lightweight, usage-driven static analysis engine designed to infer precise and contextually relevant type information without relying on statistical learning or large datasets. Typify integrates symbolic execution with iterative fixpoint analysis and a context-matching retrieval system to propagate and predict type information across entire projects. By constructing and traversing dependency graphs in an execution-aware manner, Typify accurately connects function calls to their definitions and infers usage-based type semantics, even in complex, interdependent modules. We evaluate Typify on a diverse corpus of real-world Python repositories, including the ManyTypes4Py and Typilus datasets, benchmarking its effectiveness in predicting types of variables, arguments, and return statements. Results from the evaluation show that Typify consistently matches or surpasses state-of-the-art deep learning-based systems such as Type4Py and HiTyper, as well as industry-standard static type inference tools like Pyre. Our findings demonstrate that usage-driven, retrieval-based inference can match or exceed the accuracy of data-driven methods, offering a practical, interpretable, and computationally efficient alternative for large and evolving Python codebases.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。