refactor-python

Installation
SKILL.md

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

  1. 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.
  2. Work from evidence. Read code, tests, config, docs, and call sites before changing design.
  3. Make one coherent change at a time. Prefer small, reviewable diffs over bundled redesigns.
  4. Protect risky behavior. Run existing checks; add characterization tests when coverage is missing and the refactor is not trivial.
  5. Follow the project. Match its Python version, formatter, linter, type checker, test style, package layout, and dependency manager.
  6. Avoid architecture astronautics. Add abstractions only when duplication, volatility, or dependency direction justifies them.
  7. 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

Related skills

More from jwd83/skills

Installs
5
Repository
jwd83/skills
GitHub Stars
1
First Seen
13 days ago