python-refactor

Automate Python refactorings with AST analysis and patch generation.

Updated Nov 20, 2025
One-click install
npx skills add https://github.com/Cissou34730/Azure-Architect-Assistant --skill python-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-refactor
Source: https://github.com/Cissou34730/Azure-Architect-Assistant/tree/main/.github/skills/python-refactor
Command: npx skills add https://github.com/Cissou34730/Azure-Architect-Assistant --skill python-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers perform automated, safe Python refactorings by analyzing code with the AST and generating patch-friendly changes that preserve behavior and are easy to review.

Core Features & Use Cases

  • AST-based refactor suggestions for common patterns and anti-patterns (e.g., unnecessary imports, formatting improvements, small function extractions).
  • Patch/diff outputs that enable code review and deterministic application.
  • Dry-run mode with backups and a safe apply workflow to verify changes before committing.
  • Integration with unit tests to validate behavior after refactors.

Quick Start

Use the scripts/analyze.py to scan a Python project for refactor opportunities. Use the scripts/refactor.py to generate patches (dry-run by default). Use the scripts/apply_patch.py to apply confirmed patches safely (creates backups).

Frequently Asked Questions about python-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automate Python refactoring without changing code behavior?

You can automate Python refactoring safely by using AST-based transformations to analyze code for anti-patterns and generate patch-friendly diffs that preserve behavior for easy review.

What is the best way to generate code quality patches for a large Python project?

The best way to generate code quality patches for large Python projects is to run static analysis scripts that detect formatting issues and unnecessary imports, producing deterministic dry-run diffs for review.

How does AST static analysis help with removing Python anti-patterns?

AST static analysis helps remove Python anti-patterns by parsing the abstract syntax tree to detect issues like unnecessary imports, enabling targeted structural changes and small function extractions via generated patches.

Can I apply Python refactor patches safely with a dry-run mode?

Yes, you can apply Python refactor patches safely using a dry-run workflow that generates diffs first, creates backups, and integrates with unit tests to validate behavior before committing changes.

Does AST-based Python refactoring work for medium-scale codebases?

AST-based Python refactoring is designed for medium- to large-scale Python projects needing formatting updates and anti-pattern removal, supporting deterministic patch generation and safe application across extensive codebases.