arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~

自动化即时Python类型注释更新

Automating Just-In-Time Python Type Annotation Updating

Zhipeng Xue, Zhipeng Gao, Xing Hu, Jingyuan Chen, Xin Xia, Shanping Li

arXiv 2607.09054首次发表:更新:

AI 中文总结

研究Python项目中类型注释易过时问题,提出基于大语言模型的TypeUp方法自动更新类型注释,能依据旧注释和代码更改生成新注释,性能优于现有方法,在实际项目评估中展现实用价值。

AI 中文摘要

类型注释在Python项目中越来越流行,可避免因动态类型特性导致的错误。但开发者更改源代码时,类型注释常被忽视,导致过时和不一致,阻碍程序理解、误导开发者甚至引入未来错误。本文提出通过随代码更改自动更新类型注释来减少甚至避免过时注释,即“即时(JIT)类型注释更新”。为此提出基于大语言模型的TypeUp方法,能根据旧注释和代码更改自动生成新注释。评估结果显示TypeUp在任务中比现有最佳类型推断方法TypeGen性能提升41.9%,在实际软件项目中的评估也显示了其实际价值。

英文摘要

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.

Comments12 pages, accepted by ICSE 2026

论文原文

arXiv 摘要页 · PDF 原文 · HTML 原文

↑