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

📅 2025-12-25
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Python’s dynamic typing often leads to runtime errors, and existing tools struggle to achieve high-precision, repository-scale type inference—primarily due to the difficulty of modeling complex inter-file and inter-procedural dependencies. This paper introduces the first global type inference method for large-scale Python codebases: (1) it constructs an Entity Dependency Graph (EDG) to explicitly capture cross-module type flows; (2) it designs a co-iterative optimization mechanism that jointly refines types and dependencies; and (3) it integrates a type checker-in-the-loop for real-time validation, error correction, and propagation suppression. Built upon an LLM-based reasoning framework, the approach supports automated EDG construction and incremental updates. Evaluated on 12 complex open-source repositories, TypeSim achieves 0.89 and TypeExact achieves 0.84—outperforming the strongest baseline by 27% and 40%, respectively—and eliminates 92.7% of new type errors introduced by prior tools.

Technology Category

Application Category

📝 Abstract
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 extit{TypeSim} score of 0.89 and a extit{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.
Problem

Research questions and friction points this paper is trying to address.

Addresses repository-level type inference for Python
Models complex inter-procedural dependencies via Entity Dependency Graph
Iteratively refines types and dependencies to reduce runtime errors
Innovation

Methods, ideas, or system contributions that make the work stand out.

Uses Entity Dependency Graph for repository-level type modeling
Iteratively co-evolves types and dependencies for accurate inference
Integrates type-checker-in-the-loop to reduce error propagation
🔎 Similar Papers
No similar papers found.
Shuo Sun
Shuo Sun
Johns Hopkins University
S
Shixin Zhang
Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences, China
Jiwei Yan
Jiwei Yan
Institute of Software, Chinese Academy of Sciences
Software TestingProgram AnalysisMobile Application
J
Jun Yan
Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences, China
J
Jian Zhang
Key Laboratory of System Software (Chinese Academy of Sciences), Institute of Software, Chinese Academy of Sciences, China