python-refactor

Refactor complex Python code into maintainable implementations with validation.

Updated Feb 25, 2026
One-click install
npx skills add https://github.com/Lilwenz/Geometry-Informed-Dual-Adaptive --skill python-refactor-lilwenz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-refactor
Source: https://github.com/Lilwenz/Geometry-Informed-Dual-Adaptive/tree/main/.agents/skills/python-refactor
Command: npx skills add https://github.com/Lilwenz/Geometry-Informed-Dual-Adaptive --skill python-refactor-lilwenz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires complexipy, radon, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

Complex Python codebases often become hard to read, reason about, and maintain as they grow; this Skill provides a systematic approach to transform such code into clear, well-documented, and maintainable implementations without altering observable behavior.

Core Features & Use Cases

  • Structured 4-Phase Refactoring: Analysis, Planning, Execution, and Validation workflows to guide safe code improvements.
  • Refactoring Patterns Library: Guard clauses, extract method, dictionary dispatch, OOP transformations, dependency injection, and domain modeling for progressively cleaner architectures.
  • Quality Assurance & Tooling: Regression-preventive checks (tests, static analysis, cognitive/cyclomatic metrics) and documentation coverage to ensure changes are safe and understandable.
  • Use Case: Modernize a legacy module with global state and monolithic functions, improving testability and readability while preserving behavior.

Quick Start

Provide a structured refactor for a Python module by outlining the target file, the intended pattern to apply, and the validation steps; then run the workflow to produce a traceable, test-passing refactor plan.

Frequently Asked Questions about python-refactor

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

FAQPage Schema
How do I refactor complex Python code without changing observable behavior?

Refactoring complex Python code safely requires a structured approach using static analysis, tests, and maintainability metrics to transform tangled functions into clear, maintainable implementations without altering observable behavior. This Skill enforces regression-preventive checks using Ruff, Complexipy, and Radon.

What is the best way to modernize a legacy Python module with global state?

Modernizing a legacy Python module with global state involves applying refactoring patterns like guard clauses, dependency injection, and OOP transformations. This Skill provides a 4-phase workflow—Analysis, Planning, Execution, and Validation—to incrementally improve testability and readability while preserving functionality.

How does cyclomatic and cognitive complexity help improve Python code quality?

Cyclomatic and cognitive complexity metrics measure how difficult Python code is to understand and maintain. By integrating with Complexipy and Radon, this Skill quantifies code complexity to identify tangled functions, guiding targeted refactoring efforts that yield clear, well-documented, and maintainable implementations.

Can I use this refactoring workflow on a medium-to-large Python codebase?

Yes, this refactoring workflow is designed for medium-to-large Python codebases with legacy patterns, global state, or monolithic functions. It applies structured refactoring patterns incrementally, ensuring safety through validation steps that include static analysis, maintainability metrics, and documentation coverage.

How to apply refactoring patterns like extract method and dictionary dispatch in Python?

Applying refactoring patterns like extract method and dictionary dispatch in Python involves using a structured library of transformations to progressively clean architectures. This Skill guides you through OOP transformations and domain modeling to replace complex logic with clear, maintainable code structures.

Why should I use a 4-phase refactoring workflow instead of directly modifying Python code?

A 4-phase refactoring workflow—Analysis, Planning, Execution, and Validation—prevents behavioral changes and regressions that occur when directly modifying Python code. It enforces static analysis and test validation at each step, ensuring that improvements to readability and maintainability are traceable and safe.