Making Python Code Idiomatic by Automatic Refactoring Non-Idiomatic Python Code with Pythonic Idioms
Zejun Zhang, Zhenchang Xing, Xin Xia, Xiwei Xu, Liming Zhu

TL;DR
This paper presents an automatic refactoring tool that converts non-idiomatic Python code into idiomatic Python using identified Pythonic idioms, improving code quality and consistency.
Contribution
The paper introduces a systematic approach to identify and refactor non-idiomatic Python code into idiomatic code using AST-based pattern matching and rewriting techniques.
Findings
High accuracy in detecting non-idiomatic code
Effective refactoring across diverse real-world projects
Positive developer feedback on tool usefulness
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Computational Physics and Python Applications · Software Testing and Debugging Techniques
