Automating Just-In-Time Python Type Annotation Updating
- URL: http://arxiv.org/abs/2607.09054v1
- Date: Fri, 10 Jul 2026 02:53:36 GMT
- Title: Automating Just-In-Time Python Type Annotation Updating
- Abstract summary: We argue that obsolete type annotations can be reduced and even avoided by automatically updating type annotations alongside code changes.<n>TypeUp can automatically generate new type annotations based on the old type annotations and corresponding code changes.
- Score: 26.292549325956045
- License: http://creativecommons.org/licenses/by/4.0/
- Abstract: Type annotations are more and more popular in Python projects to avoid type errors caused by Python's dynamic typing feature. However, when developers change source code, these type annotations are often neglected or overlooked, resulting in outdated and inconsistent type annotations. Such obsolete type annotations can hinder program comprehension, mislead developers, and even introduce bugs in the future. Therefore, it is necessary to avoid and correct these inconsistent type annotations from the very beginning. In this work, we argue that obsolete type annotations can be reduced and even avoided by automatically updating type annotations alongside code changes. We refer to this task as "Just-In-Time (JIT) type annotation updating". To solve this task, we propose a novel LLM-based approach named TypeUp (Type Annotation Updator) to automate this task. TypeUp can automatically generate new type annotations based on the old type annotations and corresponding code changes. Specifically, TypeUp guides LLM to perform type annotation updates by eliciting its knowledge and logical reasoning power and learning from similar code changes. The evaluation results show that TypeUp outperforms state-of-the-art type infer approach (i.e., TypeGen) by 41.9% on our task. Moreover, we conducted an in-the-wild evaluation with real-world software projects, 20 out of 25 type annotation updates generated by our approach have already been confirmed by developers, showing our approach's practical value in real-world environments.
Related papers
- Type Hints in Python Libraries and Frameworks: An Empirical Analysis of Adoption and Maintenance [0.29332247106953097]
We investigate the adoption, usage, maintenance, and rationale of type hints in Python libraries and frameworks.<n>Of the analyzed repositories, 91% of libraries use type hints at least once, although adoption is inconsistent.<n>When modified, annotations tend to migrate to more expressive types.
arXiv Detail & Related papers (2026-09-02T16:15:09Z) - Do Developers Read Type Information? An Eye-Tracking Study on TypeScript [4.249448869949738]
Statically-annotated types have been shown to aid developers in a number of programming tasks.<n>It is hypothesized that this is because developers use type annotations as in-code documentation.
arXiv Detail & Related papers (2026-02-04T18:12:59Z) - Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code [14.7995140938911]
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.
arXiv Detail & Related papers (2025-12-25T09:15:06Z) - Type-Less yet Type-Aware Inductive Link Prediction with Pretrained Language Models [47.6332883113148]
We introduce TyleR, a Type-less yet type-awaRe approach for subgraph-based inductive link prediction.<n>We show that TyleR outperforms state-of-the-art baselines in scenarios with scarce type annotations and sparse graph connectivity.
arXiv Detail & Related papers (2025-09-30T13:23:02Z) - RightTyper: Effective and Efficient Type Annotation for Python [0.7673339435080445]
RightTyper generates precise type annotations based on actual program behavior.<n>RightTyper is fast and space-efficient, imposing just 30% performance overhead on average.
arXiv Detail & Related papers (2025-07-21T20:37:35Z) - 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) - Understanding How CodeLLMs (Mis)Predict Types with Activation Steering [6.975009142727399]
Research shows that Large Language Models (LLMs) often lack a deep understanding of program semantics.<n>In this work, we examine the task of type prediction.<n>We show that steering successfully activates a type prediction mechanism that is shared by both Python and TypeScript.
arXiv Detail & Related papers (2024-04-02T12:44:44Z) - 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) - Annotation Error Detection: Analyzing the Past and Present for a More
Coherent Future [63.99570204416711]
We reimplement 18 methods for detecting potential annotation errors and evaluate them on 9 English datasets.
We define a uniform evaluation setup including a new formalization of the annotation error detection task.
We release our datasets and implementations in an easy-to-use and open source software package.
arXiv Detail & Related papers (2022-06-05T22:31:45Z) - Annotation Curricula to Implicitly Train Non-Expert Annotators [56.67768938052715]
voluntary studies often require annotators to familiarize themselves with the task, its annotation scheme, and the data domain.
This can be overwhelming in the beginning, mentally taxing, and induce errors into the resulting annotations.
We propose annotation curricula, a novel approach to implicitly train annotators.
arXiv Detail & Related papers (2021-06-04T09:48:28Z) - 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) - LambdaNet: Probabilistic Type Inference using Graph Neural Networks [46.66093127573704]
This paper proposes a probabilistic type inference scheme for TypeScript based on a graph neural network.
Our approach can predict both standard types, like number or string, as well as user-defined types that have not been encountered during training.
arXiv Detail & Related papers (2020-04-29T17:48:40Z)
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.