py-refactor
Installation
SKILL.md
Python Refactoring & Performance
Overview
Safe refactoring patterns, type safety enforcement, and performance optimization for Python/FastAPI backends.
Core principle: Never refactor without characterization tests. Never optimize without profiling. Always improve type coverage.
3-strikes rule: If the same refactoring approach fails 3 times, stop. The problem is architectural — escalate to system-design for a deeper review instead of thrashing.
Safe Refactoring Process
- Write characterization tests — capture current behavior
- Run mypy — baseline type errors
- Refactor — change structure, preserve behavior
- Verify — tests pass, mypy errors same or fewer
- Clean up — remove temporary tests if redundant