一句话:提出基于 LLM 的 TypeUp,利用代码变更与旧标注即时更新 Python 类型标注,并显著优于 TypeGen。
Python 的动态类型易引发类型错误,类型标注可缓解该问题,但源码变更后标注常未同步,导致过时、不一致,影响理解并可能引入缺陷。论文提出“即时(JIT)类型标注更新”任务,并设计基于 LLM 的方法 TypeUp。它根据旧类型标注和对应代码变更生成新标注,通过激发 LLM 的知识与逻辑推理能力,并借鉴相似代码变更来指导更新。评估显示,在该任务上 TypeUp 比最先进的类型推断方法 TypeGen 高 41.9%。在真实项目应用中,25 个更新有 20 个获开发者确认,表明其实用价值。
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 the state-of-the-art type inference approach (i.e., TypeGen) by 41.9% on our task. Moreover, we conducted a practical application 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.