Making Python Code More Pythonic with AI

Making Python Code More Pythonic with AI

Using LLMs to Automatically Refactor Non-Idiomatic Code

This research explores how Large Language Models can transform non-idiomatic Python code into more expressive, efficient, and maintainable idiomatic constructs.

  • LLMs achieved comparable or better results than specialized static analysis tools in refactoring Python code
  • The approach successfully handled 9 different idiomatic patterns with high accuracy
  • Models showed strong capabilities in preserving semantic equivalence while improving code quality
  • Fine-tuned models outperformed generalist LLMs on this specific task

For engineering teams, this represents a significant advancement in automated code improvement that can enhance productivity, maintainability, and standardization of Python codebases without manual intervention.

Automated Refactoring of Non-Idiomatic Python Code: A Differentiated Replication with LLMs

101 | 323