python-package-refactoring

Plan and execute incremental refactoring of Python package code with test validation.

Updated Apr 20, 2026
One-click install
npx skills add https://github.com/MLVisions/agentbuilder_py --skill python-package-refactoring-mlvisions
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-package-refactoring
Source: https://github.com/MLVisions/agentbuilder_py/tree/main/.github/skills/python-package-refactoring
Command: npx skills add https://github.com/MLVisions/agentbuilder_py --skill python-package-refactoring-mlvisions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring a Python package without breaking existing functionality is risky and error-prone. This Skill provides a systematic workflow for restructuring code, reducing duplication, and improving modularity while keeping tests green and avoiding regressions. ## Core Features & Use Cases - Structured Refactoring Workflow: Follow a four-phase process of identifying problems, planning changes, making incremental edits, and validating with pytest after each step. - Proven Refactoring Patterns: Apply concrete before/after patterns such as extract function, consolidate similar functions, centralize configuration, standardize parameter order, and use Protocols/ABCs/singledispatch. - Breaking Change Management: Handle deprecations safely with warnings, changelogs, and pre/post-refactor checklists covering tests, docs, and git commits. - Use Case: When a package has grown to contain duplicated tool-building functions and inconsistent parameter ordering, use this Skill to plan the consolidation, migrate callers incrementally, and verify each change with targeted pytest runs. ## Quick Start Refactor the duplicated tool-building functions in this package into a single dispatcher while keeping all tests passing.

Frequently Asked Questions about python-package-refactoring

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

FAQPage Schema
How do I refactor a Python package without breaking existing functionality?▼

Make incremental changes one logical step at a time: add the new function or pattern, update tests, migrate old code, then remove the old code. Run targeted pytest tests after each notable change to catch regressions early.

How to consolidate similar Python functions into one?▼

When several functions differ only by type or minor logic, create a single function with a type parameter that dispatches to private builder functions via a dictionary. Only consolidate when it reduces code, improves maintainability, and keeps clarity.

When should I use Protocol or ABC instead of conditionals in Python?▼

Use Protocols, ABCs, or functools.singledispatch when conditional logic is scattered across the codebase and polymorphism would reduce complexity. This centralizes behavior contracts and cuts down the lines of code you must maintain.

How do I handle breaking changes when refactoring a Python package?▼

Add a DeprecationWarning to the old function that forwards to the new one, then remove the old function in the next major version. Update the CHANGELOG, documentation, and examples alongside the removal.

What tests should I run after refactoring Python code?▼

Run relevant tests first with pytest -k matching the affected pattern rather than the full suite, to save time and API calls. Ensure every exported function has coverage and never weaken test expectations just to make tests pass.