Lune

ICSE2024Top-tier venue

Domain Knowledge Matters: Improving Prompts with Fix Templates for Repairing Python Type Errors

Yun Peng, Shuzheng Gao, Cuiyun Gao, Yintong Huo, Michael R. Lyu

Abstract

As a dynamic programming language, Python has become increasingly popular in recent years. Although the dynamic type system of Python facilitates the developers in writing Python programs, it also brings type errors at run-time which are prevalent yet not easy to fix. There exist rule-based approaches for automatically repairing Python type errors. The approaches can generate accurate patches for the type errors covered by manually defined templates, but they require domain experts to design patch synthesis rules and suffer from low template coverage of real-world type errors. Learningbased approaches alleviate the manual efforts in designing patch synthesis rules and have become prevalent due to the recent advances in deep learning. Among the learning-based approaches, the prompt-based approach which leverages the knowledge base of code pre-trained models via pre-defined prompts, obtains stateof-the-art performance in general program repair tasks. However, such prompts are manually defined and do not involve any specific clues for repairing Python type errors, resulting in limited effectiveness. How to automatically improve prompts with the domain knowledge for type error repair is challenging yet under-explored. In this paper, we present TypeFix, a novel prompt-based approach with fix templates incorporated for repairing Python type errors. TypeFix first mines generalized fix templates via a novel hierarchical clustering algorithm. The identified fix templates indicate the common edit patterns and contexts of existing type error fixes. TypeFix then generates code prompts for code pre-trained models by employing the generalized fix templates as domain knowledge, in which the masks are adaptively located for each type error instead of being pre-determined. Experiments on two benchmarks, including BugsInPy and TypeBugs, show that TypeFix successfully repairs 26 and 55 type errors, outperforming the best baseline

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.

15 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

  • Generative Type Inference for Python cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Generative Type Inference for Python cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Generative Type Inference for Python cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • Generative Type Inference for Python cites Language Models are Few-Shot Learners
  • Search-Based LLMs for Code Optimization cites Generative Type Inference for Python
  • Search-Based LLMs for Code Optimization cites Language Models are Few-Shot Learners
  • Search-Based LLMs for Code Optimization cites What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs?
  • CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Template-Guided Program Repair in the Era of Large Language Models cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • Template-Guided Program Repair in the Era of Large Language Models cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Template-Guided Program Repair in the Era of Large Language Models cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs? cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs? cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs? cites Language Models are Few-Shot Learners
  • Seeing is Fixing: Cross-Modal Reasoning with Multimodal LLMs for Visual Software Issue Repair cites CoCoNuT: combining context-aware neural translation models using ensemble for program repair
  • Seeing is Fixing: Cross-Modal Reasoning with Multimodal LLMs for Visual Software Issue Repair cites Template-Guided Program Repair in the Era of Large Language Models
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers15

  1. What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs?Shuzheng Gao, Xin-Cheng Wen, Cuiyun Gao, Wenxuan Wang et al.ASE 2023 · 80 citations
  2. Generative Type Inference for PythonYun Peng, Chaozheng Wang, Wenxuan Wang, Cuiyun Gao et al.ASE 2023 · 29 citations
  3. Search-Based LLMs for Code OptimizationShuzheng Gao, Cuiyun Gao, Wenchao Gu, Michael R. LyuICSE 2025 · 11 citations
  4. Template-Guided Program Repair in the Era of Large Language ModelsKai Huang, Jian Zhang, Xiangxin Meng, Yang LiuICSE 2025 · 7 citations
  5. Seeing is Fixing: Cross-Modal Reasoning with Multimodal LLMs for Visual Software Issue RepairKai Huang, Jian Zhang, Xiaofei Xie, Chunyang ChenASE 2025 · 5 citations

Builds on19

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. 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
  3. GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
  4. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
  5. 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

Related papers

  1. TFix: Learning to Fix Coding Errors with a Text-to-Text TransformerBerkay Berabi, Jingxuan He, Veselin Raychev, Martin T. VechevICML 2021 · 143 citations
  2. PyTER: effective program repair for Python type errorsWonseok Oh, Hakjoo OhFSE 2022 · 22 citations
  3. ThinkRepair: Self-Directed Automated Program RepairXin Yin, Chao Ni, Shaohua Wang, Zhenhao Li et al.ISSTA 2024 · 37 citations
  4. PyTy: Repairing Static Type Errors in PythonYiu Wai Chow, Luca Di Grazia, Michael PradelICSE 2024 · 13 citations
  5. Less training, more repairing please: revisiting automated program repair via zero-shot learningChunqiu Steven Xia, Lingming ZhangFSE 2022 · 223 citations
Dusk over the sea between two cliffs drawn in fine vertical lines