refactor-python
Refactor Python
Purpose
Refactor Python code safely and idiomatically while preserving behavior. Optimize for readable code, simple module boundaries, explicit contracts, useful tests, and maintainable Python. Avoid importing patterns from other ecosystems when simple functions, modules, dataclasses, protocols, or standard-library tools fit better.
Use this skill for cleanup, simplification, renaming, decomposition, dependency untangling, test characterization, typing improvements, packaging cleanup, or async/data-model refactors. Do not treat a rewrite, redesign, feature, or performance project as a refactor unless the user explicitly asks for that scope.
Non-Negotiables
- Preserve behavior. Keep public APIs, CLI flags, exceptions, log messages, file formats, ordering, database schemas, and side effects compatible unless the user approves a breaking change.
- Work from evidence. Read code, tests, config, docs, and call sites before changing design.
- Make one coherent change at a time. Prefer small, reviewable diffs over bundled redesigns.
- Protect risky behavior. Run existing checks; add characterization tests when coverage is missing and the refactor is not trivial.
- Follow the project. Match its Python version, formatter, linter, type checker, test style, package layout, and dependency manager.
- Avoid architecture astronautics. Add abstractions only when duplication, volatility, or dependency direction justifies them.
- Do not hide behavior changes inside cleanup. If you discover a bug, report it or fix it in a separate, explicit change.
First Inspection Checklist
More from jwd83/skills
system-verilog-expert
Expert SystemVerilog guidance for RTL, interfaces, and verification-adjacent code with EDA-friendly design patterns. Use when designing, reviewing, or refactoring hardware-oriented SystemVerilog and when spotting HDL antipatterns that cause timing, lint, CDC, or tool-flow pain.
14simplify
Simplifies and refines code for clarity, consistency, and maintainability while preserving all functionality. Focuses on recently modified code unless instructed otherwise.
11grill-me
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
10wiki-me
Build or extend a project wiki — a persistent, interlinked markdown knowledge base that the LLM incrementally maintains from your sources. Use when the user wants to start a wiki, add new sources, or synthesize notes into a living knowledge base rather than one-off RAG.
10godot-gdscript-patterns
Master Godot 4 GDScript patterns including signals, scenes, state machines, and optimization. Use when building Godot games, implementing game systems, or learning GDScript best practices.
10next-step
Resume an in-progress codebase from its actual current state, identify the next smallest defensible implementation step, make that change, and update tests, docs, or plans to match. Use when a rewrite, migration, refactor, feature, or cleanup is underway and you want the agent to move the work forward safely without inventing a whole new roadmap.
7