python-refactoring
Python refactoring catalog with 83 patterns covering immutability, class design, control flow, architecture, OO metrics, and Python idioms. Analyze code for smells and apply numbered refactoring patterns with before/after examples. Use when the user invokes /refactor or explicitly asks to refactor, clean up, or improve Python code quality.
What this skill does
# Python Refactoring Skill 83 refactoring patterns from Contieri's series, Fowler's catalog, OO metrics literature, and Python idioms. ## Modes **Active Analysis** (default when given code): Identify smells -> map to patterns -> load relevant references -> apply refactorings with before/after -> note trade-offs. **Reference Lookup** (when asked about a pattern by number/name): Load the relevant reference file -> present the pattern. ## Smell-to-Pattern Map | Code Smell | Patterns | File | |---|---|---| | Setters / half-built objects | SC101, SC104 | state.md | | Mutable default args | SC701 | idioms.md | | Unprotected public attributes | SC103 | state.md | | Magic numbers / constants | SC601 | hygiene.md | | Variables that never change | SC102 | state.md | | Boolean flags for roles/states | SC105 | state.md | | Stale cached/derived attributes | 030 | state.md | | Long function, multiple concerns | SC201, 010 | functions.md | | Comments replacing code | 005 | functions.md | | Comments explaining what code does | 011 | hygiene.md | | Generic names (result, data, tmp) | SC202 | functions.md | | Duplicated logic | SC606 | hygiene.md | | Near-duplicate functions | 050 | functions.md | | Long related parameter lists | SC206, 052 | functions.md | | Query + modify in same function | SC207 | functions.md | | Static functions hiding deps | 020 | functions.md | | `input()` in business logic | SC203 | functions.md | | Getters exposing data | 027 | functions.md | | Need to test private methods | 037 | functions.md | | Unused function parameters | SC208 | functions.md | | Long lambda expressions | SC209 | functions.md | | Type-checking if/elif chains | SC302 | types.md | | `isinstance()` dispatch | 060 | idioms.md | | Dicts as objects (stringly-typed) | 012 | types.md | | Raw primitives with implicit rules | 019, 044 | types.md | | Raw lists, no domain meaning | 038 | types.md | | Boilerplate `__init__/__repr__/__eq__` | SC304 | idioms.md | | Related functions without a class | SC301 | types.md | | Sibling classes with duplicate behavior | 022 | types.md | | Inheritance without "is-a" | 023 | types.md | | Constructor needs descriptive name | 048 | types.md | | Scattered `None` checks | 015, SC204 | types.md | | Lazy class (too few methods) | SC306 | types.md | | Temporary fields (used in few methods) | SC307 | types.md | | Deep nesting | SC402 | control.md | | Imperative loops with accumulation | SC403 | control.md | | Complex boolean expressions | SC404 | control.md | | Long expressions, no named parts | 043 | control.md | | Loop doing two things | 046 | control.md | | Parse/compute/format mixed | 047 | control.md | | Clunky algorithm | 049 | control.md | | Boolean flag controlling loop | SC405 | control.md | | Complex if/elif dispatch | 056 | control.md | | Related statements scattered | 053 | control.md | | Missing default else branch | SC407 | control.md | | Complex comprehensions | SC406 | control.md | | Singleton / global state | SC303, SC106 | architecture.md | | Same exception for biz + infra | 035 | architecture.md | | Chained `.attr.attr.attr` | SC502 | architecture.md | | No fail-fast assertions | 045 | architecture.md | | Dead code / commented blocks | SC401 | hygiene.md | | Unused exceptions | SC602 | hygiene.md | | Empty catch blocks | SC605 | hygiene.md | | Giant regex | 025 | hygiene.md | | Excessive decorators | SC205 | hygiene.md | | String concatenation for multiline | SC603 | hygiene.md | | Inconsistent formatting | 032 | hygiene.md | | Cryptic error messages | 031 | hygiene.md | | Sequential IDs leaking info | SC107 | architecture.md | | Error codes instead of exceptions | SC501 | architecture.md | | Blocking calls in async functions | SC703 | idioms.md | | Manual try/finally cleanup | SC702, SC604 | idioms.md | | Full lists when streaming works | 059 | idioms.md | | Indexing tuples by position | SC305 | idioms.md | | Shotgun surgery (wide call spread) | SC505 | architecture.md | | Deep inheritance tree | SC308 | types.md | | Wide hierarchy (too many subclasses) | SC309 | types.md | | Inappropriate intimacy | SC506 | architecture.md | | Speculative generality (unused ABCs) | SC507 | architecture.md | | Unstable dependency | SC508 | architecture.md | | Low class cohesion (LCOM) | SC801 | metrics.md | | High coupling between objects (CBO) | SC802 | metrics.md | | Excessive fan-out | SC803 | metrics.md | | High response for class (RFC) | SC804 | metrics.md | | Middle man (excessive delegation) | SC805 | metrics.md | ## Reference Files Load **only** the file(s) matching detected smells: - `references/state.md` -- Immutability, setters, attributes (SC101, SC102, SC103, SC104, SC105, 030) - `references/functions.md` -- Method extraction, naming, parameters, CQS (SC201, 005, SC202, 010, 020, SC203, 027, SC206, 037, SC207, 050, 052, SC208, SC209) - `references/types.md` -- Class design, reification, polymorphism, nulls (SC301, 012, SC302, 015, 019, 022, 023, SC204, 038, 044, 048, SC306, SC307, SC308, SC309) - `references/control.md` -- Guard clauses, pipelines, conditionals, phases (SC402-SC404, 043, 046, 047, 049, 053, SC405, 056, SC406, SC407) - `references/architecture.md` -- DI, singletons, exceptions, delegates (SC303, SC106, SC107, 035, 045, SC501, SC502, SC505, SC506, SC507, SC508) - `references/hygiene.md` -- Constants, dead code, comments, style (SC601, SC602, 011, SC606, SC401, 025, 031-032, SC205, SC603, SC605) - `references/idioms.md` -- Context managers, generators, unpacking, protocols, async (SC701, SC702, SC703, 059, 060, SC304, SC305, SC604) - `references/metrics.md` -- OO metrics: cohesion, coupling, fan-out, response, delegation (SC801, SC802, SC803, SC804, SC805) ## Automated Smell Detector `scripts/detect_smells.py` runs the smell detector with 56 automated checks (41 per-file + 10 cross-file + 5 OO metrics). It ships with a bundled copy of the smellcheck package — no pip install required. ```bash # Works immediately after skill install — no pip required python3 scripts/detect_smells.py src/ python3 scripts/detect_smells.py myfile.py --format json # Look up rule documentation (description + before/after example) python3 scripts/detect_smells.py --explain SC701 python3 scripts/detect_smells.py --explain SC4 # list a family python3 scripts/detect_smells.py --explain all # list all rules # Caching (enabled by default — skips unchanged files on repeat scans) python3 scripts/detect_smells.py src/ --no-cache # fresh scan python3 scripts/detect_smells.py --clear-cache # purge cache # Or use the pip-installed CLI directly pip install smellcheck smellcheck src/ --min-severity warning --fail-on warning ``` **Per-file detections** (41): SC101 setters, SC201 long functions, SC601 magic numbers, SC602 bare except, SC202 generic names, SC301 extract class, SC102 UPPER_CASE without Final, SC103 public attrs, SC302 isinstance chains, SC104 half-built objects, SC105 boolean flags, SC303 singleton, SC401 dead code after return, SC106 global mutables, SC203 input() in logic, SC107 sequential IDs, SC204 return None|list, SC205 excessive decorators, SC206 too many params, SC603 string concatenation, SC402 deep nesting, SC403 loop+append, SC207 CQS violation, SC404 complex booleans, SC501 error codes, SC502 Law of Demeter, SC405 control flags, SC701 mutable defaults, SC702 open without with, SC703 blocking calls in async, SC304 dataclass candidate, SC305 sequential indexing, SC604 contextlib candidate, SC210 cyclomatic complexity, SC208 unused parameters, SC605 empty catch block, SC209 long lambda, SC406 complex comprehension, SC407 missing else, SC306 lazy class, SC307 temporary field. **Cross-file detections** (10): SC606 duplicate functions (AST-normalized hashing), SC503 cyclic imports (DFS), SC504 god modules, SC211 feature envy, SC505 shotgun surgery, SC308 deep inheritance, SC309 wide hierarchy, SC506 inappropriate intimacy, SC507 speculative generality, SC508 unstable dependency. **OO metrics** (5): SC80
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.