# Python Refactor

> Guidance for refactoring Python code to improve clarity and maintainability. Use this skill when the user asks to simplify Python logic, restructure functions, or improve code quality.

- Skill: `adryledo/python-refactor` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add adryledo/python-refactor`
- Raw SKILL.md: https://api.skillmd.com/api/skills/adryledo/python-refactor/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: Apache-2.0
- Author: adryledo (https://skillmd.com/u/adryledo)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/adryledo/python-refactor

---


# Python Refactor Skill

This skill provides practical steps for improving Python code structure and readability.

## Goals

- Improve maintainability  
- Simplify complex logic  
- Clarify naming and responsibilities  
- Remove unused or redundant code  

## Recommended Process

### 1. Analyze the structure
Identify:
- Functions, classes, modules  
- Deep nesting or long functions  
- Side effects and repeated logic  

### 2. Detect common issues
Look for:
- Unclear naming  
- Duplicate logic  
- Unreachable code  
- Long parameter lists  
- Mutable default arguments  

### 3. Apply refactoring techniques
Use patterns such as:
- Extract Function  
- Inline Variable  
- Replace Temp with Query  
- Introduce Parameter Object  
- Remove Dead Code  
- Simplify Conditional Expressions  

### 4. Produce output
Return:
- The refactored code  
- A short explanation of changes  
- Any recommended follow‑up improvements  

## Example

**Input**

[`scripts/process.py`](scripts/process.py)
