paperbot · PL 论文追踪

全部论文 待读 收藏

P1 PyTy: Repairing Static Type Errors in Python

PyTy:修复 Python 中的静态类型错误
ICSE Proceedings of the IEEE/ACM 46th International Conference on Software Engineering2024匹配度 5/10 · 该论文面向 Python 静态类型错误的自动修复,属于机器学习与程序语言/静态分析的交叉方向,并构建了缺陷数据集、做了实证与工业 PR 验证;但它使用的是学习式修复模型而非 LLM/Agent,也未涉及浮点程序分析或贝叶斯程序分析,与画像中的核心问题仅部分重合。引用 18 inbox
Yiu Wai Chow, Luca Di Grazia, Michael Pradel
crossref: 2026-09-12

AI 速览

一句话:提出 PyTy,首个基于学习的 Python 静态类型错误自动修复技术,利用跨语言迁移学习并在真实错误上达 85.4% 修复率。

渐进类型让 Python 开发者可自选类型标注,但静态检查器报告的大量类型错误仍需手工修复。本文提出 PyTy,面向 Python 静态类型错误的自动程序修复。作者先实证研究开发者修复模式,发现多种策略与重复模式;再自动抽取错误-修复对,构建来自 176 个 GitHub 仓库、含 2,766 对样本的 PyTyDefects。核心是受数据稀缺启发、采用跨语言迁移学习的神经修复模型。评估显示,PyTy 覆盖十类常见错误,在 281 个真实错误上修复 85.4%,优于先进大语言模型 2.1 倍,可与运行时错误修复互补;30 个 PR 中 20 个被合并。

问题
随着渐进类型在 Python 中普及,静态类型检查器报告大量类型错误,而手动修复这些错误成本高,阻碍了渐进类型的实际采用。
方法
PyTy 通过实证研究开发者修复模式,自动抽取错误-修复对构建 PyTyDefects 数据集,并训练基于跨语言迁移学习的神经模型来生成修复。
评估
在 281 个真实世界类型错误上评估,PyTy 成功修复 85.4%,比先进 LLM 高 2.1 倍,且 30 个建议修复的 PR 中有 20 个被开发者合并。
原文摘要(Abstract)

Gradual typing enables developers to annotate types of their own choosing, offering a flexible middle ground between no type annotations and a fully statically typed language. As more and more code bases get type-annotated, static type checkers detect an increasingly large number of type errors. Unfortunately, fixing these errors requires manual effort, hampering the adoption of gradual typing in practice. This paper presents PyTy, an automated program repair approach targeted at statically detectable type errors in Python. The problem of repairing type errors deserves specific attention because it exposes particular repair patterns, offers a warning message with hints about where and how to apply a fix, and because gradual type checking serves as an automatic way to validate fixes. We addresses this problem through three contributions: (i) an empirical study that investigates how developers fix Python type errors, showing a diverse set of fixing strategies with some recurring patterns; (ii) an approach to automatically extract type error fixes, which enables us to create a dataset of 2,766 error-fix pairs from 176 GitHub repositories, named PyTyDefects; (iii) the first learning-based repair technique for fixing type errors in Python. Motivated by the relative data scarcity of the problem, the neural model at the core of PyTy is trained via cross-lingual transfer learning. Our evaluation shows that PyTy offers fixes for ten frequent categories of type errors, successfully addressing 85.4% of 281 real-world errors. This effectiveness outperforms state-of-the-art large language models asked to repair type errors (by 2.1x) and complements a previous technique aimed at type errors that manifest at runtime. Finally, 20 out of 30 pull requests with PyTy-suggested fixes have been merged by developers, showing the usefulness of PyTy in practice.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@inproceedings{paperbot11330,
  title = {PyTy: Repairing Static Type Errors in Python},
  author = {Yiu Wai Chow and Luca Di Grazia and Michael Pradel},
  booktitle = {ICSE},
  year = {2024},
  doi = {10.1145/3597503.3639184}
}