arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.21591cs.SE
收藏

类型与依赖的共进化:面向Python代码仓库级类型的推断

Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code

Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所软件工程中心);Key Laboratory of System Software (Chinese Academy of Sciences), Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所系统软件重点实验室)

Shuo Sun, Shixin Zhang, Jiwei Yan, Jun Yan, Jian Zhang

AI总结:

本文提出\methodName,通过类型与依赖的共进化实现Python仓库级类型推断,显著提升类型推断准确率并减少新错误。

摘要:

Python的动态类型机制虽然促进了灵活性,但却是大规模软件中导致运行时类型错误的主要原因,这激励了自动类型推断技术的发展。现有的类型推断工具在孤立代码片段中的类型推断方面取得了进展。然而,仓库级类型推断仍是一个重大挑战,主要由于复杂的跨过程依赖关系难以建模和解决。为填补这一空白,我们提出了\methodName,一种基于大语言模型(LLMs)的新方法,通过类型与依赖的共进化实现仓库级类型推断。\methodName构建了一个实体依赖图(EDG)来建模仓库中的对象和类型依赖关系。在推断过程中,它通过迭代优化EDG中的类型和依赖关系以实现精确的类型推断。我们的关键创新包括:(1)一个设计用于捕捉仓库级类型依赖关系的EDG模型;(2)一种迭代类型推断方法,其中类型和依赖在每次迭代中共同进化;(3)一种类型检查器在循环中的策略,该策略在推断过程中验证并纠正推断结果,从而减少错误传播。在对12个复杂Python仓库的评估中,\methodName显著优于先前的工作,实现了\textit{TypeSim}得分为0.89和\textit{TypeExact}得分为0.84,分别比最强基线提高了27%和40%。更重要的是,\methodName减少了工具引入的新类型错误达92.7%。这表明在自动化、可靠的Python开发中类型注解方面取得了重大进展。

英文摘要:

Python's dynamic typing mechanism, while promoting flexibility, is a significant source of runtime type errors that plague large-scale software, which inspires the automatic type inference techniques. Existing type inference tools have achieved advances in type inference within isolated code snippets. However, repository-level type inference remains a significant challenge, primarily due to the complex inter-procedural dependencies that are difficult to model and resolve. To fill this gap, we present \methodName, a novel approach based on LLMs that achieves repository-level type inference through the co-evolution of types and dependencies. \methodName~constructs an Entity Dependency Graph (EDG) to model the objects and type dependencies across the repository. During the inference process, it iteratively refines types and dependencies in EDG for accurate type inference. Our key innovations are: (1) an EDG model designed to capture repository-level type dependencies; (2) an iterative type inference approach where types and dependencies co-evolve in each iteration; and (3) a type-checker-in-the-loop strategy that validates and corrects inferences on-the-fly, thereby reducing error propagation. When evaluated on 12 complex Python repositories, \methodName~significantly outperformed prior works, achieving a \textit{TypeSim} score of 0.89 and a \textit{TypeExact} score of 0.84, representing a 27\% and 40\% relative improvement over the strongest baseline. More importantly, \methodName~removed new type errors introduced by the tool by 92.7\%. This demonstrates a significant leap towards automated, reliable type annotation for real-world Python development.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑