Python Expert Best Practices Code Review

wispbit-ai/skills/skills/python-expert-best-practices-code-review

作者 wispbit-ai8b2c7d0ceca0MIT8 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

Python best practices for writing production-grade code. This skill should be used when writing, reviewing, or refactoring Python code. Triggers on tasks involving Python development, error handling patterns, dictionary operations, and code quality improvements.

AI 生成的概览

用于按八条最佳实践规则编写、审查和重构生产级 Python 代码的指南。

功能
该技能提供一套按优先级组织的 Python 最佳实践准则,涵盖错误处理、常见缺陷、代码清晰度和代码风格。它指向八个独立规则文件,每个文件包含说明、适用与不适用场景、实现要求,以及错误与正确的代码示例。它产出的是审查建议和重构指导,而非可执行结果。
适用场景
适用于编写 Python 函数、类或模块,审查 Python 代码中的错误处理或质量问题,或重构现有 Python 代码库。也适用于实现数据校验与 API 边界,以及改进错误检测和调试模式。
运行要求
无需任何工具、软件包或凭据;仅为说明与参考文档,不附带脚本。

Python 3.14+ Expert Best Practices

Simple, pragmatic, opinionated. Only what matters for writing production-grade python code.

When to Apply

Reference these guidelines when:

  • Writing Python functions, classes, or modules
  • Reviewing Python code for error handling issues
  • Refactoring existing Python codebases
  • Implementing data validation and API boundaries
  • Optimizing error detection and debugging patterns

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Error HandlingCRITICALdict-, operators-
2Common BugsCRITICAL-HIGHno-mutable-, no-generic-
3Code ClarityHIGH-MEDIUMlistcomp-, no-inline-
4Code StyleLOWavoid-, unnecessary-

Quick Reference

  • dict-required-keys - Use d[key] for required dictionary keys to fail fast with KeyError
  • no-mutable-defaults - No mutable defaults in function/method parameters
  • operators-return-notimplemented - Return NotImplemented for unsupported operand types and design + vs += intentionally
  • no-generic-except - Avoid generic except clauses to prevent hiding unexpected errors
  • listcomp-no-side-effects - List comprehensions must produce a value you use (no side-effect listcomps)
  • no-inline-imports - Place all import statements at the top of the file
  • avoid-explanatory-comments - Avoid unnecessary comments for self-documenting code
  • unnecessary-else-blocks - Avoid unnecessary else blocks after return/break/continue statements

How to Use

Read individual rule files for detailed explanations and code examples:

rules/dict-required-keys.mdrules/no-mutable-defaults.mdrules/operators-return-notimplemented.mdrules/no-generic-except.mdrules/listcomp-no-side-effects.mdrules/no-inline-imports.mdrules/avoid-explanatory-comments.mdrules/unnecessary-else-blocks.md

Each rule file contains:

  • Brief explanation of why it matters
  • When to use and when not to use the pattern
  • Implementation requirements
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

来源与署名

来源:wispbit-ai/skills位于skills/python-expert-best-practices-code-review提交8b2c7d0

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架