AGENT SKILL

code-refactor

Refactor Python code to match this repo's coding standards and style. Use when the user asks to "refactor", "clean up", "fix coding standards", or "apply best practices" to a module, file, or directory in this repo. Applies python-best-practices, pydantic v2, pytorch-lightning, and python-docs conventions as relevant to the target code.

适用职业开发工程师
使用场景代码审查
License 许可
MIT
最近更新
2026-09-17
Stars
★ 5
Forks
0

01 前言 Front Matter

name
code-refactor
description
Refactor Python code to match this repo's coding standards and style. Use when the user asks to "refactor", "clean up", "fix coding standards", or "apply best practices" to a module, file, or directory in this repo. Applies python-best-practices, pydantic v2, pytorch-lightning, and python-docs conventions as relevant to the target code.

02 资源文件 4

03 SKILL.md 正文

Code Refactor Skill

Systematically refactor Python code to match this repo's standards.

Workflow

1. Read Target Code

Read every file in the target module. Never propose changes to code you haven't read.

2. Audit Against Checklist

Run through references/checklist.md and note every violation. Group them by category so the user can see the full picture before any edits are made.

3. Run Static Analysis

uv run ruff check <target>
uv run mypy <target>

Report all errors as part of the audit — these are additional violations on top of the checklist.

4. Apply Fixes

Apply all fixes. Prefer the Edit tool over Write for existing files (smaller diffs, easier review). Make all independent edits in parallel.

Priority order (highest impact first):

  1. Type safety — enums over bare strings, from __future__ import annotations, proper return types
  2. Pydantic — snake_case fields with aliases, model_config, field validators (see references/pydantic-patterns.md)
  3. Error handling — replace assert with if/raise, add context to re-raised exceptions
  4. Python best practices — frozen dataclasses, Protocol types, avoid mutable defaults
  5. PyTorch/Lightning — only apply if the module contains torch or nn.Module code (see references/pytorch-patterns.md)
  6. Docs — public functions must have docstrings (see references/docs-patterns.md)

5. Verify

uv run ruff check <target>
uv run ruff format <target>
uv run mypy <target>
uv run pytest tests/unit/<target-name>/ -v

All checks must pass before declaring done. If tests fail, fix them — don't skip.

6. Summarise

Report a table of every change made, grouped by category. Include file and line references.


Repo-Specific Conventions

  • Python: 3.12 — use StrEnum, match, X | Y unions, from __future__ import annotations in every file
  • Linter/Formatter: Ruff (88 char line length)
  • Type checker: mypy (strict — all errors must be resolved)
  • Package manager: uv (uv run <cmd>)
  • Tests: pytest, mirror source structure under tests/unit/
  • Logging: from logging_utils import get_logger then logger = get_logger(__name__) — never logging.getLogger(__name__) or print()
  • Imports: stdlib → third-party → local, each group separated by blank line
  • Config: TOML or YAML only — never JSON for config files

When to Apply Each Sub-Skill

Code contains Apply
BaseModel, Pydantic fields references/pydantic-patterns.md
torch, nn.Module, LightningModule references/pytorch-patterns.md
Public classes / functions without docstrings references/docs-patterns.md
All Python files references/checklist.md

04 同仓库更多 Skills

arnabdeypolimi
arnabdeypolimi/claude_code_setup

git-operations

暂无简介

★ 5
arnabdeypolimi
arnabdeypolimi/claude_code_setup

python-best-practices

暂无简介

★ 5
arnabdeypolimi
arnabdeypolimi/claude_code_setup

typst-paper

Typst academic paper assistant for existing `.typ` paper projects in English or Chinese. Use this skill whenever the user wants to compile, audit, or improve a Typst paper, including format checks, bibliography validation for BibTeX or Hayagriva, grammar/sentence/logic review, expression polishing, translation, title optimization, pseudocode review, algorithm block cleanup, de-AI editing, or experiment-section review. Trigger even when the user only mentions one Typst file, one bibliography issue, one pseudocode block, or one section rewrite. Also trigger when the user mentions ".typ files", "typst compile error", "typst export", "typst bibliography", `algorithm-figure`, `lovelace`, or `algorithmic` even without saying the word "Typst" explicitly.

写作与文案资料检索与研究
★ 5
arnabdeypolimi
arnabdeypolimi/claude_code_setup

typeset

Improves typography by fixing font choices, hierarchy, sizing, weight, and readability so text feels intentional. Use when the user mentions fonts, type, readability, text hierarchy, sizing looks off, or wants more polished, intentional typography.

★ 5
arnabdeypolimi
arnabdeypolimi/claude_code_setup

teach-impeccable

One-time setup that gathers design context for your project and saves it to your AI config file. Run once to establish persistent design guidelines.

设计师教师与教育视觉设计
★ 5
arnabdeypolimi
arnabdeypolimi/claude_code_setup

research-paper-writing

Improve academic paper writing quality for ML/CV/NLP-style papers with clear section structure, paragraph flow, and reviewer-facing presentation. Use when drafting or revising Abstract, Introduction, Related Work, Method, Experiments, or Conclusion; polishing figures/tables; checking claim-support alignment; or performing self-review before submission.

内容创作者写作与文案资料检索与研究
★ 5