Making Python code idiomatic by automatic refactoring non-idiomatic Python code with pythonic idioms
摘要
Compared to other programming languages (e.g., Java), Python has more idioms to make Python code concise and efficient. Although pythonic idioms are well accepted in the Python community, Python programmers are often faced with many challenges in using them, for example, being unaware of certain pythonic idioms or do not know how to use them properly. Based on an analysis of 7,638 Python repositories on GitHub, we find that non-idiomatic Python code that can be implemented with pythonic idioms occurs frequently and widely. Unfortunately, there is no tool for automatically refactoring such non-idiomatic code into idiomatic code. In this paper, we design and implement an automatic refactoring tool to make Python code idiomatic. We identify nine pythonic idioms by systematically contrasting the abstract syntax grammar of Python and Java. Then we define the syntactic patterns for detecting nonidiomatic code for each pythonic idiom. Finally, we devise atomic AST-rewriting operations and refactoring steps to refactor nonidiomatic code into idiomatic code. We test and review over 4,115 refactorings applied to 1,065 Python projects from GitHub, and submit 90 pull requests for the 90 randomly sampled refactorings to 84 projects. These evaluations confirm the high-accuracy, practicality and usefulness of our refactoring tool on real-world Python code. Our refactoring tool can be accessed at 47.242.131.128:5000.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 6 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- A Study on the Pythonic Functional Constructs' Understandability 引用了 Faster or Slower? Performance Mystery of Python Idioms Unveiled with Empirical Evidence
- Refactoring to Pythonic Idioms: A Hybrid Knowledge-Driven Approach Leveraging Large Language Models 引用了 PYEVOLVE: Automating Frequent Code Changes in Python ML Systems
- Refactoring to Pythonic Idioms: A Hybrid Knowledge-Driven Approach Leveraging Large Language Models 引用了 Faster or Slower? Performance Mystery of Python Idioms Unveiled with Empirical Evidence
- Refactoring to Pythonic Idioms: A Hybrid Knowledge-Driven Approach Leveraging Large Language Models 引用了 Unprecedented Code Change Automation: The Fusion of LLMs and Transformation by Example
- PYEVOLVE: Automating Frequent Code Changes in Python ML Systems 引用了 Discovering Repetitive Code Changes in Python ML Systems
- Unprecedented Code Change Automation: The Fusion of LLMs and Transformation by Example 引用了 Discovering Repetitive Code Changes in Python ML Systems
- Unprecedented Code Change Automation: The Fusion of LLMs and Transformation by Example 引用了 PYEVOLVE: Automating Frequent Code Changes in Python ML Systems
引用它的顶会 Paper6
- PYEVOLVE: Automating Frequent Code Changes in Python ML SystemsMalinda Dilhara, Danny Dig, Ameya KetkarICSE 2023 · 46 次引用
- Unprecedented Code Change Automation: The Fusion of LLMs and Transformation by ExampleMalinda Dilhara, Abhiram Bellur, Timofey Bryksin, Danny DigFSE 2024 · 18 次引用
- Faster or Slower? Performance Mystery of Python Idioms Unveiled with Empirical EvidenceZejun Zhang, Zhenchang Xing, Xin Xia, Xiwei Xu 等ICSE 2023 · 16 次引用
- Refactoring to Pythonic Idioms: A Hybrid Knowledge-Driven Approach Leveraging Large Language ModelsZejun Zhang, Zhenchang Xing, Xiaoxue Ren, Qinghua Lu 等FSE 2024 · 11 次引用
- A Study on the Pythonic Functional Constructs' UnderstandabilityCyrine Zid, Fiorella Zampetti, Giuliano Antoniol, Massimiliano Di PentaICSE 2024 · 4 次引用
它引用的 Paper4
- Reinforcement learning based curiosity-driven testing of Android applicationsMinxue Pan, An Huang, Guoxin Wang, Tian Zhang 等ISSTA 2020 · 166 次引用
- Exploring how deprecated Python library APIs are (not) handledJiawei Wang, Li Li, Kui Liu, Haipeng CaiFSE 2020 · 52 次引用
- Automating the removal of obsolete TODO commentsZhipeng Gao, Xin Xia, David Lo, John C. Grundy 等FSE 2021 · 34 次引用
- Discovering Repetitive Code Changes in Python ML SystemsMalinda Dilhara, Ameya Ketkar, Nikhith Sannidhi, Danny DigICSE 2022 · 30 次引用
相关 Paper
- Hard to Read and Understand Pythonic Idioms? DeIdiom and Explain Them in Non-Idiomatic Equivalent CodeZejun Zhang, Zhenchang Xing, Dehai Zhao, Qinghua Lu 等ICSE 2024 · 7 次引用
- PyNose: A Test Smell Detector For PythonTongjie Wang, Yaroslav Golubev, Oleg Smirnov, Jiawei Li 等ASE 2021 · 44 次引用
- Learning to find naming issues with big code and small supervisionJingxuan He, Cheng-Chun Lee, Veselin Raychev, Martin T. VechevPLDI 2021 · 9 次引用
- DyLin: A Dynamic Linter for PythonAryaz Eghbali, Felix Burk, Michael PradelFSE 2025 · 1 次引用
- The untold story of code refactoring customizations in practiceDaniel Oliveira, Wesley K. G. Assunção, Alessandro F. Garcia, Ana Carla Bibiano 等ICSE 2023 · 11 次引用
