Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code
- URL: http://arxiv.org/abs/2512.21591v1
- Date: Thu, 25 Dec 2025 09:15:06 GMT
- Title: Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code
- Authors: Shuo Sun, Shixin Zhang, Jiwei Yan, Jun Yan, Jian Zhang,
- Abstract summary: Python's dynamic typing mechanism, while promoting flexibility, is a significant source of runtime type errors.<n>We present methodName, a novel approach that achieves repository-level type inference through the co-evolution of types and dependencies.<n>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.
- Score: 14.7995140938911
- License: http://arxiv.org/licenses/nonexclusive-distrib/1.0/
- 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 \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.
Related papers
- ResAD++: Towards Class Agnostic Anomaly Detection via Residual Feature Learning [52.11294707895649]
This paper explores the problem of class-agnostic anomaly detection (AD)<n>The objective is to train one class-agnostic AD model that can generalize to detect anomalies in diverse new classes from different domains without any retraining or fine-tuning on the target data.<n> Comprehensive experiments on eight real-world AD datasets demonstrate that our ResAD++ can achieve remarkable AD results when directly used in new classes.
arXiv Detail & Related papers (2025-09-28T08:41:05Z) - TypyBench: Evaluating LLM Type Inference for Untyped Python Repositories [9.127866457704162]
Large language models (LLMs) have shown promise in code understanding, but their type inference capabilities remain underexplored.<n>We introduce TypyBench, a benchmark designed to evaluate LLMs' type inference across entire Python repositories.<n>Our evaluation of various LLMs on a curated dataset of 50 high-quality Python repositories reveals that, although LLMs achieve decent TypeSim scores, they struggle with complex nested types and exhibit significant type consistency errors.
arXiv Detail & Related papers (2025-07-28T14:54:00Z) - Type-Constrained Code Generation with Language Models [51.03439021895432]
We introduce a type-constrained decoding approach that leverages type systems to guide code generation.<n>For this purpose, we develop novel prefix automata and a search over inhabitable types, forming a sound approach to enforce well-typedness on LLM-generated code.<n>Our approach reduces compilation errors by more than half and significantly increases functional correctness in code synthesis, translation, and repair tasks.
arXiv Detail & Related papers (2025-04-12T15:03:00Z) - TIGER: A Generating-Then-Ranking Framework for Practical Python Type Inference [16.192704604206206]
Python's dynamic typing system offers flexibility and expressiveness but can lead to type-related errors.
We introduce TIGER, a two-stage generating-then-ranking (GTR) framework to handle Python's diverse type categories.
Our evaluation on the ManyTypes4Py dataset shows TIGER's advantage over existing methods in various type categories.
arXiv Detail & Related papers (2024-07-02T09:29:02Z) - ArcheType: A Novel Framework for Open-Source Column Type Annotation using Large Language Models [24.867534196627222]
We introduce ArcheType, a simple, practical method for context sampling, prompt serialization, model querying, and label remapping.
We establish a new state-of-the-art performance on zero-shot CTA benchmarks.
arXiv Detail & Related papers (2023-10-27T15:31:22Z) - Generative Type Inference for Python [62.01560866916557]
This paper introduces TypeGen, a few-shot generative type inference approach that incorporates static domain knowledge from static analysis.
TypeGen creates chain-of-thought (COT) prompts by translating the type inference steps of static analysis into prompts based on the type dependency graphs (TDGs)
Experiments show that TypeGen outperforms the best baseline Type4Py by 10.0% for argument type prediction and 22.5% in return value type prediction in terms of top-1 Exact Match.
arXiv Detail & Related papers (2023-07-18T11:40:31Z) - TypeT5: Seq2seq Type Inference using Static Analysis [51.153089609654174]
We present a new type inference method that treats type prediction as a code infilling task.
Our method uses static analysis to construct dynamic contexts for each code element whose type signature is to be predicted by the model.
We also propose an iterative decoding scheme that incorporates previous type predictions in the model's input context.
arXiv Detail & Related papers (2023-03-16T23:48:00Z) - DORE: Document Ordered Relation Extraction based on Generative Framework [56.537386636819626]
This paper investigates the root cause of the underwhelming performance of the existing generative DocRE models.
We propose to generate a symbolic and ordered sequence from the relation matrix which is deterministic and easier for model to learn.
Experimental results on four datasets show that our proposed method can improve the performance of the generative DocRE models.
arXiv Detail & Related papers (2022-10-28T11:18:10Z) - Bilateral Dependency Optimization: Defending Against Model-inversion
Attacks [61.78426165008083]
We propose a bilateral dependency optimization (BiDO) strategy to defend against model-inversion attacks.
BiDO achieves the state-of-the-art defense performance for a variety of datasets, classifiers, and MI attacks.
arXiv Detail & Related papers (2022-06-11T10:07:03Z) - Decoupled Multi-task Learning with Cyclical Self-Regulation for Face
Parsing [71.19528222206088]
We propose a novel Decoupled Multi-task Learning with Cyclical Self-Regulation for face parsing.
Specifically, DML-CSR designs a multi-task model which comprises face parsing, binary edge, and category edge detection.
Our method achieves the new state-of-the-art performance on the Helen, CelebA-HQ, and LapaMask datasets.
arXiv Detail & Related papers (2022-03-28T02:12:30Z) - Context-aware Entity Typing in Knowledge Graphs [12.181416235996302]
Knowledge graph entity typing aims to infer entities' missing types in knowledge graphs.
This paper proposes a novel method for this task by utilizing entities' contextual information.
Experiments on two real-world KGs demonstrate the effectiveness of our method.
arXiv Detail & Related papers (2021-09-16T13:59:27Z) - Type4Py: Deep Similarity Learning-Based Type Inference for Python [9.956021565144662]
We present Type4Py, a deep similarity learning-based type inference model for Python.
We design a hierarchical neural network model that learns to discriminate between types of the same kind and dissimilar types in a high-dimensional space.
Considering the Top-1 prediction, Type4Py obtains 19.33% and 13.49% higher precision than Typilus and TypeWriter, respectively.
arXiv Detail & Related papers (2021-01-12T13:32:53Z)
This list is automatically generated from the titles and abstracts of the papers in this site.
This site does not guarantee the quality of this site (including all information) and is not responsible for any consequences.