界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
数据与研究 · SKILL.md

python-best-practices

python-best-practices

【数据与研究】Write maintainable Python with small functions, explicit boundaries, guard clauses, and readable state flow. Use when refactoring Python services, helpers, modules, or async logic for clarity—not generic test writing, tooling setup, or database transaction implementation.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: python-best-practices description: Write maintainable Python with small functions, explicit boundaries, guard clauses, and readable state flow. Use when refactoring Python services, helpers, modules, or async logic for clarity—not generic test writing, tooling setup, or database transaction implementation. metadata: triggers: files: - "**/*.py" keywords: - refactor - clean code - readability - guard clause - composition

Python Best Practices

Priority: P1 (HIGH)

Rules

  • Prefer small focused functions over long stateful procedures.
  • Push parsing, formatting, transport, and persistence into separate helpers.
  • Return early on invalid or terminal states.
  • Pass collaborators in; do not hide them behind globals or import-time singletons.
  • Keep naming literal and domain-specific.

Recipe

  1. Split orchestration from transformation.
  2. Extract repeated shape cleanup into one helper.
  3. Keep side effects at edges and pure decisions in the middle.
  4. Use fakes in tests instead of patching deep internal chains when possible.

Anti-Patterns

  • No god functions: break report builders and workflow loops into tested slices.
  • No boolean soup: name decision helpers instead of stacking flags inline.
  • No hidden retries: surface retry policy near the call site.
  • No print-debugging in shared runtime code: use structured logging or test assertions.

References

我的收藏