dignified-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDignified Python Coding Standards
高标准Python编码规范
Core Knowledge (ALWAYS Loaded)
核心知识(始终加载)
@dignified-python-core.md
@dignified-python-core.md
Version Detection
版本检测
Identify the project's minimum Python version by checking (in order):
- - Look for
pyproject.tomlfield (e.g.,requires-python)requires-python = ">=3.12" - or
setup.py- Look forsetup.cfgpython_requires - file - Contains version like
.python-versionor3.123.12.0 - Default to Python 3.12 if no version specifier found
Once identified, load the appropriate version-specific file:
- Python 3.10: Load
versions/python-3.10.md - Python 3.11: Load
versions/python-3.11.md - Python 3.12: Load
versions/python-3.12.md - Python 3.13: Load
versions/python-3.13.md
按以下顺序检查,确定项目的最低Python版本:
- - 查找
pyproject.toml字段(例如requires-python)requires-python = ">=3.12" - 或
setup.py- 查找setup.cfgpython_requires - 文件 - 包含类似
.python-version或3.12的版本号3.12.0 - 若未找到版本说明,默认使用Python 3.12
确定版本后,加载对应的版本专属文件:
- Python 3.10: 加载
versions/python-3.10.md - Python 3.11: 加载
versions/python-3.11.md - Python 3.12: 加载
versions/python-3.12.md - Python 3.13: 加载
versions/python-3.13.md
Conditional Loading (Load Based on Task Patterns)
条件加载(根据任务模式加载)
Core files above cover 80%+ of Python code patterns. Only load these additional files when you detect specific patterns:
Pattern detection examples:
- If task mentions "click" or "CLI" -> Load
cli-patterns.md - If task mentions "subprocess" -> Load
subprocess.md
上述核心文件覆盖了80%以上的Python代码场景。仅当检测到特定模式时才加载以下额外文件:
模式检测示例:
- 若任务提及"click"或"CLI" -> 加载
cli-patterns.md - 若任务提及"subprocess" -> 加载
subprocess.md
When to Read Each Reference Document
各参考文档的适用场景
The directory contains detailed guidance for specialized topics. Load these on-demand when you encounter relevant patterns:
references/references/references/exception-handling.md
references/exception-handling.mdreferences/exception-handling.md
references/exception-handling.mdRead when:
- Writing try/except blocks
- Wrapping third-party APIs that may raise
- Seeing or writing or
from efrom None - Unsure if LBYL alternative exists
适用场景:
- 编写try/except代码块
- 封装可能抛出异常的第三方API
- 遇到或编写或
from e代码from None - 不确定是否存在LBYL替代方案时
references/interfaces.md
references/interfaces.mdreferences/interfaces.md
references/interfaces.mdRead when:
- Creating ABC or Protocol classes
- Writing @abstractmethod decorators
- Designing gateway layer interfaces
- Choosing between ABC and Protocol
适用场景:
- 创建ABC或Protocol类
- 编写@abstractmethod装饰器
- 设计网关层接口
- 需要在ABC和Protocol之间做选择时
references/typing-advanced.md
references/typing-advanced.mdreferences/typing-advanced.md
references/typing-advanced.mdRead when:
- Using typing.cast()
- Creating Literal type aliases
- Narrowing types in conditional blocks
适用场景:
- 使用typing.cast()时
- 创建Literal类型别名时
- 在条件代码块中做类型收窄时
references/module-design.md
references/module-design.mdreferences/module-design.md
references/module-design.mdRead when:
- Creating new Python modules
- Adding module-level code (beyond simple constants)
- Using @cache decorator at module level
- Seeing Path() or computation at module level
- Considering inline imports
适用场景:
- 创建新的Python模块时
- 添加模块级代码(简单常量之外的内容)时
- 在模块级别使用@cache装饰器时
- 遇到模块级的Path()调用或计算逻辑时
- 考虑使用内联导入时
references/api-design.md
references/api-design.mdreferences/api-design.md
references/api-design.mdRead when:
- Adding default parameter values to functions
- Defining functions with 5 or more parameters
- Using ThreadPoolExecutor.submit()
- Reviewing function signatures
适用场景:
- 为函数添加默认参数值时
- 定义参数数量≥5的函数时
- 使用ThreadPoolExecutor.submit()时
- 评审函数签名时
references/checklists.md
references/checklists.mdreferences/checklists.md
references/checklists.mdRead when:
- Final review before committing Python code
- Unsure if you've followed all rules
- Need a quick lookup of requirements
适用场景:
- 提交Python代码前的最终评审
- 不确定是否遵守了所有规则时
- 需要快速查询规范要求时
How to Use This Skill
如何使用本规范
- Core knowledge is loaded automatically (LBYL, pathlib, basic imports, anti-patterns)
- Version detection happens once - identify the minimum Python version and load the appropriate version file
- Reference documents are loaded on-demand based on the triggers above
- Additional patterns may require extra loading (CLI patterns, subprocess)
- Each file is self-contained with complete guidance for its domain
- 核心知识自动加载(LBYL、pathlib、基础导入、反模式)
- 版本检测仅执行一次:确定最低Python版本并加载对应版本文件
- 参考文档根据上述触发条件按需加载
- 特殊场景可能需要额外加载(CLI模式、subprocess)
- 每个文件都自包含,对应领域的指引完整独立