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

06/02/2023
by   Yun Peng, et al.
0

Although the dynamic type system of Python facilitates the developers in writing Python programs, it also brings type errors at run-time. There exist rule-based approaches for automatically repairing Python type errors. The approaches can generate accurate patches but they require domain experts to design patch synthesis rules and suffer from low template coverage of real-world type errors. Learning-based approaches alleviate the manual efforts in designing patch synthesis rules. Among the learning-based approaches, the prompt-based approach which leverages the knowledge base of code pre-trained models via pre-defined prompts, obtains state-of-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 approach by 9 and 14, respectively. Besides, the proposed fix template mining approach can cover 75 increasing the best rule-based approach PyTER by more than 30

READ FULL TEXT

page 1

page 2

page 3

page 4

research
02/03/2023

KNOD: Domain Knowledge Distilled Tree Decoder for Automated Program Repair

Automated Program Repair (APR) improves software reliability by generati...
research
09/17/2023

GAMMA: Revisiting Template-based Automated Program Repair via Mask Prediction

Automated program repair (APR) aims to fix software bugs without human i...
research
07/18/2023

Generative Type Inference for Python

Python is a popular dynamic programming language, evidenced by its ranki...
research
04/14/2022

GLAD: Neural Predicate Synthesis to Repair Omission Faults

Existing template and learning-based APR tools have successfully found p...
research
07/17/2022

Less Training, More Repairing Please: Revisiting Automated Program Repair via Zero-shot Learning

Due to the promising future of Automated Program Repair (APR), researche...
research
03/18/2023

Revisiting the Plastic Surgery Hypothesis via Large Language Models

Automated Program Repair (APR) aspires to automatically generate patches...
research
11/22/2022

OLGA : An Ontology and LSTM-based approach for generating Arithmetic Word Problems (AWPs) of transfer type

Machine generation of Arithmetic Word Problems (AWPs) is challenging as ...

Please sign up or login with your details

Forgot password? Click here to reset