ActRef: Enhancing the Understanding of Python Code Refactoring with Action-Based Analysis
Siqi Wang, Xing Hu, Xinyu Wang, Xin Xia · ACM Transactions on Software Engineering and Methodology · 2026
Refactoring is the process of improving the code structure of a software system without altering its behavior. It is crucial for managing code evolution in software development. Identifying refactoring actions in source code is essential for understanding software evolution and guiding developers in maintaining and improving code quality. However, existing tools frequently struggle to detect complex and diverse refactoring types in Python, because most of them are designed for Java-centric environments. This limitation hinders their ability to address Python's dynamic and flexible syntax effectively. This study presents an action-based Refactoring Analysis Framework named ActRef , a novel algorithm designed to advance the detection and understanding of Python refactorings through a unique code change action-based analysis of code changes. ActRef mines 15 refactoring types (e.g., move, rename, extract, and inline operations) based on diff actions, covering 4 granularity levels, including variable, method, class, and module levels. By focusing on the code change actions, ActRef provides a Python-adaptive solution to detect intricate refactoring patterns. Our evaluation is conducted on 1,915 manually validated refactoring instances from 136 open-source Python projects. The evaluation results show that ActRef achieves high precision (0.80) and recall (0.92), effectively identifying 15 refactoring types. Compared with leading baselines, including PyRef, PyRef with MLRefScanner, DeepSeek-R1, and ChatGPT-4, ActRef consistently demonstrates superior performance in detecting Python refactorings across various types. While matching PyRef in runtime efficiency, ActRef supports a broader spectrum of refactoring types and more refactoring mining levels. ActRef shows an effective and scalable approach for mining refactorings in dynamic Python codebases and introduces a new perspective on understanding code.