PyTy: Repairing Static Type Errors in Python
Yiu Wai Chow, Luca Di Grazia, Michael Pradel
摘要
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.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 9 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- RepairAgent: An Autonomous, LLM-Based Agent for Program Repair 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- RepairAgent: An Autonomous, LLM-Based Agent for Program Repair 引用了 AutoCodeRover: Autonomous Program Improvement
- RepairAgent: An Autonomous, LLM-Based Agent for Program Repair 引用了 Automated Program Repair in the Era of Large Pre-trained Language Models
- CodeCureAgent: Automatic Classification and Repair of Static Analysis Warnings 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- CodeCureAgent: Automatic Classification and Repair of Static Analysis Warnings 引用了 RepairAgent: An Autonomous, LLM-Based Agent for Program Repair
- LLM-Based Repair of Static Nullability Errors 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- LLM-Based Repair of Static Nullability Errors 引用了 RepairAgent: An Autonomous, LLM-Based Agent for Program Repair
- LLM-Based Repair of Static Nullability Errors 引用了 AutoCodeRover: Autonomous Program Improvement
- AutoCodeRover: Autonomous Program Improvement 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- AutoCodeRover: Autonomous Program Improvement 引用了 Automated Program Repair in the Era of Large Pre-trained Language Models
- Less training, more repairing please: revisiting automated program repair via zero-shot learning 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- Less training, more repairing please: revisiting automated program repair via zero-shot learning 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Less training, more repairing please: revisiting automated program repair via zero-shot learning 引用了 GraphCodeBERT: Pre-training Code Representations with Data Flow
- Automated Program Repair in the Era of Large Pre-trained Language Models 引用了 CoCoNuT: combining context-aware neural translation models using ensemble for program repair
- Automated Program Repair in the Era of Large Pre-trained Language Models 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Automated Program Repair in the Era of Large Pre-trained Language Models 引用了 Less training, more repairing please: revisiting automated program repair via zero-shot learning
引用它的顶会 Paper9
- AutoCodeRover: Autonomous Program ImprovementYuntong Zhang, Haifeng Ruan, Zhiyu Fan, Abhik RoychoudhuryISSTA 2024 · 96 次引用
- RepairAgent: An Autonomous, LLM-Based Agent for Program RepairIslem Bouzenia, Premkumar T. Devanbu, Michael PradelICSE 2025 · 54 次引用
- Reflections on the Reproducibility of Commercial LLM Performance in Empirical Software Engineering StudiesFlorian Angermeir, Maximilian Amougou, Mark Kreitz, Andreas Bauer 等ICSE 2026 · 1 次引用
- CodeCureAgent: Automatic Classification and Repair of Static Analysis WarningsPascal Joos, Islem Bouzenia, Michael PradelFSE 2026
- LLM-Based Repair of Static Nullability ErrorsNima Karimipour, Pascal Joos, Michael Pradel, Martin Kellogg 等ISSTA 2026
它引用的 Paper20
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan 等EMNLP Findings 2020 · 2,828 次引用
- GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng 等ICLR 2021 · 1,644 次引用
- CoCoNuT: combining context-aware neural translation models using ensemble for program repairThibaud Lutellier, Hung Viet Pham, Lawrence Pang, Yitong Li 等ISSTA 2020 · 325 次引用
- Automated Program Repair in the Era of Large Pre-trained Language ModelsChunqiu Steven Xia, Yuxiang Wei, Lingming ZhangICSE 2023 · 321 次引用
- Less training, more repairing please: revisiting automated program repair via zero-shot learningChunqiu Steven Xia, Lingming ZhangFSE 2022 · 223 次引用
相关 Paper
- The evolution of type annotations in python: an empirical studyLuca Di Grazia, Michael PradelFSE 2022 · 29 次引用
- PyTER: effective program repair for Python type errorsWonseok Oh, Hakjoo OhFSE 2022 · 22 次引用
- Taming type annotations in gradual typingJohn Peter Campora III, Sheng ChenOOPSLA 2020 · 7 次引用
- Domain Knowledge Matters: Improving Prompts with Fix Templates for Repairing Python Type ErrorsYun Peng, Shuzheng Gao, Cuiyun Gao, Yintong Huo 等ICSE 2024 · 39 次引用
- Automating Just-In-Time Python Type Annotation UpdatingZhipeng Xue, Zhipeng Gao, Xing Hu, Jingyuan Chen 等ICSE 2026
