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 從公開儲存庫中收錄這些內容。

檢舉或申請下架