Automating Just-In-Time Python Type Annotation Updating

πŸ“… 2026-07-09
πŸ“ˆ Citations: 0
✨ Influential: 0
πŸ“„ PDF
πŸ€– AI Summary
This work addresses the challenge that code changes in Python projects frequently render type annotations outdated, compromising code readability and introducing potential errors. To tackle this issue, the authors propose TypeUpβ€”the first approach that leverages large language models (LLMs) for just-in-time type annotation updates. TypeUp synergistically combines the knowledge-based reasoning capabilities of LLMs with patterns derived from historically similar code modifications to automatically synchronize type annotations upon code edits. Experimental results demonstrate that TypeUp achieves a 41.9% higher accuracy than the current state-of-the-art method, TypeGen, on a newly constructed benchmark. Furthermore, in real-world project evaluations, developers accepted 20 out of 25 TypeUp-generated predictions, underscoring its practical effectiveness and utility.
πŸ“ 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.
Problem

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

type annotation
code change
inconsistency
Python
Just-In-Time
Innovation

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

Just-In-Time Type Annotation
LLM-based Code Update
Type Annotation Consistency
Automated Type Inference
Python Type Checking
πŸ”Ž Similar Papers