Lune

ICSE2024Top-tier venue

PyTy: Repairing Static Type Errors in Python

Yiu Wai Chow, Luca Di Grazia, Michael Pradel

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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

9 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • RepairAgent: An Autonomous, LLM-Based Agent for Program Repair cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • RepairAgent: An Autonomous, LLM-Based Agent for Program Repair cites AutoCodeRover: Autonomous Program Improvement
  • RepairAgent: An Autonomous, LLM-Based Agent for Program Repair cites Automated Program Repair in the Era of Large Pre-trained Language Models
  • CodeCureAgent: Automatic Classification and Repair of Static Analysis Warnings cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • CodeCureAgent: Automatic Classification and Repair of Static Analysis Warnings cites RepairAgent: An Autonomous, LLM-Based Agent for Program Repair
  • LLM-Based Repair of Static Nullability Errors cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • LLM-Based Repair of Static Nullability Errors cites RepairAgent: An Autonomous, LLM-Based Agent for Program Repair
  • LLM-Based Repair of Static Nullability Errors cites AutoCodeRover: Autonomous Program Improvement
  • AutoCodeRover: Autonomous Program Improvement cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • AutoCodeRover: Autonomous Program Improvement cites 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 cites 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 cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Less training, more repairing please: revisiting automated program repair via zero-shot learning cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • Automated Program Repair in the Era of Large Pre-trained Language Models cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • Automated Program Repair in the Era of Large Pre-trained Language Models cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Automated Program Repair in the Era of Large Pre-trained Language Models cites Less training, more repairing please: revisiting automated program repair via zero-shot learning
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers9

  1. AutoCodeRover: Autonomous Program ImprovementYuntong Zhang, Haifeng Ruan, Zhiyu Fan, Abhik RoychoudhuryISSTA 2024 · 96 citations
  2. RepairAgent: An Autonomous, LLM-Based Agent for Program RepairIslem Bouzenia, Premkumar T. Devanbu, Michael PradelICSE 2025 · 54 citations
  3. Reflections on the Reproducibility of Commercial LLM Performance in Empirical Software Engineering StudiesFlorian Angermeir, Maximilian Amougou, Mark Kreitz, Andreas Bauer et al.ICSE 2026 · 1 citation
  4. CodeCureAgent: Automatic Classification and Repair of Static Analysis WarningsPascal Joos, Islem Bouzenia, Michael PradelFSE 2026
  5. LLM-Based Repair of Static Nullability ErrorsNima Karimipour, Pascal Joos, Michael Pradel, Martin Kellogg et al.ISSTA 2026

Builds on20

  1. CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
  2. GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
  3. CoCoNuT: combining context-aware neural translation models using ensemble for program repairThibaud Lutellier, Hung Viet Pham, Lawrence Pang, Yitong Li et al.ISSTA 2020 · 325 citations
  4. Automated Program Repair in the Era of Large Pre-trained Language ModelsChunqiu Steven Xia, Yuxiang Wei, Lingming ZhangICSE 2023 · 321 citations
  5. Less training, more repairing please: revisiting automated program repair via zero-shot learningChunqiu Steven Xia, Lingming ZhangFSE 2022 · 223 citations

Related papers

  1. The evolution of type annotations in python: an empirical studyLuca Di Grazia, Michael PradelFSE 2022 · 29 citations
  2. PyTER: effective program repair for Python type errorsWonseok Oh, Hakjoo OhFSE 2022 · 22 citations
  3. Taming type annotations in gradual typingJohn Peter Campora III, Sheng ChenOOPSLA 2020 · 7 citations
  4. Domain Knowledge Matters: Improving Prompts with Fix Templates for Repairing Python Type ErrorsYun Peng, Shuzheng Gao, Cuiyun Gao, Yintong Huo et al.ICSE 2024 · 39 citations
  5. Automating Just-In-Time Python Type Annotation UpdatingZhipeng Xue, Zhipeng Gao, Xing Hu, Jingyuan Chen et al.ICSE 2026
Dusk over the sea between two cliffs drawn in fine vertical lines