/good-skills:python-refactoringfrom good-skills
Python 代码重构技能,覆盖代码坏味道识别、设计模式应用、可读性改进和实战经验。当用户要求"重构代码"、"refactor"、"代码优化"、"改善代码质量"、"code smell review"、"应用设计模式"、"提升可读性",或提交代码审查请求时使用此技能。支持在重构完成后输出结构化重构文档("输出重构文档"、"生成重构报告")。包含基于 vllm-ascend 仓库 20+ 个真实重构 PR 提炼的实战模式。
Ships in good-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
对 Python 代码进行系统性重构,在不改变外部行为的前提下改善内部结构,提升可读性、可维护性和可扩展性。
refactoring-config.json,用户可自定义或禁用| 任务 | 参考文档 |
|---|---|
| 自定义约束阈值 | refactoring-config.json |
| 识别代码问题 | references/code-smells.md |
| 选择设计模式 | references/design-patterns.md |
| 改善可读性 | references/readability.md |
| 实战模式与案例 | references/refactoring-in-practice.md |
| 生成重构文档 | references/refactoring-report.md |
发现问题后,用此表快速定位解决方案:
| 坏味道 | 推荐模式 | 详细参考 |
|---|---|---|
| 过长函数 | Extract Method、Guard Clause | code-smells.md §1.1 |
| 过长参数列表 | dataclass 参数对象、Builder | design-patterns.md §1.3 |
| 重复代码(横切关注点) | 装饰器模式 | design-patterns.md §2.1 |
| 重复代码(流程骨架相同) | 模板方法 / 策略模式 | practice §模式三 |
| 上帝类 | 按职责拆分、组合替代继承 | practice §模式二、五 |
| 过度继承 | 组合 + Protocol | design-patterns.md §3.1 |
| if-elif 创建实例 | 工厂模式(注册表) | practice §模式一 |
| if-elif 类型分发 | 多态 / singledispatch | design-patterns.md §3.4 |
多个 xxx_with_yyy 函数变体 | 策略模式(Protocol) | practice §模式三 |
| dict/tuple 传递复合数据 | dataclass 类型形式化 | practice §模式七 |
| 魔法数字/字符串 | 枚举(Enum / IntEnum) | code-smells.md §3.3 |
| 自定义实现与上游重复 | 对齐上游 / 继承基类 | practice §模式四 |
| 过大模块(>500 行) | 分离关注点、包化 | practice §模式二 |
| 基准测试证明的劣势路径 | 删除死路径 | practice §模式六 |
┌─────────────────────────────────────────────────────────┐
│ 0. 前置检查 │
│ - 确认有测试覆盖(无则先补关键路径测试) │
│ - 确认代码可正常运行 │
│ - 评估重构规模 → refactoring-in-practice.md 规模矩阵 │
├─────────────────────────────────────────────────────────┤
│ 1. 识别问题 → references/code-smells.md │
│ - 通读代码,按分类逐项检查 │
│ - 输出问题清单,按严重程度排序 │
├─────────────────────────────────────────────────────────┤
│ 2. 选择策略 → references/refactoring-in-practice.md │
│ - 匹配七大实战模式,选择最合适的重构路径 │
│ - 大型重构制定分阶段计划(参考 Quantization/MoE 案例) │
├─────────────────────────────────────────────────────────┤
│ 3. 结构重构 → references/design-patterns.md │
│ - 对结构性问题选择合适的模式 │
│ - 实施重构,确保接口兼容 │
├─────────────────────────────────────────────────────────┤
│ 4. 打磨优化 → references/readability.md │
│ - 改善命名、结构、类型标注 │
│ - 补充必要注释和文档 │
├─────────────────────────────────────────────────────────┤
│ 5. 验证 │
│ - 运行全部已有测试,确认无回归 │
│ - 运行 linter / type checker │
│ - 对比重构前后,确认行为一致 │
├─────────────────────────────────────────────────────────┤
│ 6. 输出重构文档(可选,用户请求时生成) │
│ - 汇总本次重构的完整记录 │
│ - 生成结构化文档,可用于 PR 描述 / 团队分享 / 项目归档 │
│ - 参见 references/refactoring-report.md │
└─────────────────────────────────────────────────────────┘
| 规模 | 范围 | 建议 | 参考案例 |
|---|---|---|---|
| 小型 | 单个函数/方法 | 直接修改,单次提交 | MoE #5189 复用上游 all_reduce(-38 行) |
| 中型 | 单个类或模块 | 拆分为 2-3 次提交 | MoE #5481 dict/tuple → dataclass(6 文件) |
| 大型 | 跨模块/包 | 制定计划,分阶段执行 | Quantization 4 阶段重构(36 文件) |
当用户请求生成重构文档(如 "输出重构文档"、"生成重构报告"、"写重构总结")时,在重构完成并验证后,按 references/refactoring-report.md 中的模板生成文档。
文档支持按用途裁剪(PR 描述 / 团队分享 / 项目归档),小型重构可使用精简格式。详见参考文档。
对每个重构建议,按以下格式输出:
### [问题类型] 问题简述
**位置:** `file_path:line_number`
**问题:** 描述当前代码的问题
**方案:** 描述修复方案
**实战参考:** 匹配的实战模式(如适用)
**修复前:**
(代码片段)
**修复后:**
(代码片段)
**依据:** 引用的参考文档和具体规则
详细参考文档:
references/code-smells.md (opens in a new tab)references/design-patterns.md (opens in a new tab)references/readability.md (opens in a new tab)references/refactoring-config.json (opens in a new tab)references/refactoring-in-practice.md (opens in a new tab)references/refactoring-report.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
26 skills in this plugin
/arxiv-daily每日 arXiv AI 论文精选系统。自动从 arXiv 抓取最新 cs.AI/cs.LG/cs.CL/cs.CV/cs.RO 论文,用 DeepSeek 评分筛选,生成中文摘要,通过邮件和 Bark 推送。/claude-apiReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration.
TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens).
SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file)./code-walkthrough为代码仓库生成面向专家评审的代码讲解材料,并可选地为 .c/.py 源文件补充中文注释。当用户说"讲解代码""代码讲解""给专家讲这个特性""梳理主流程和重点函数""这个模块怎么讲""准备评审材料""代码走读",或要求给 .c/.py 文件加文件头注释/函数注释时使用。核心能力:先问用户是否要加注释(默认不加,绝不擅自改源码),再按"一句话定调 → 全景图 → 主流程链路 → 重点函数 → 证据 → 预判追问"的结构输出讲解内容,所有结论必须带真实文件路径与行号。不用于从零起草无源码的文档,也不用于普通文档润色或翻译。npx claudepluginhub sunchendd/good_skills --plugin good-skills