dignified-python

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Dignified Python Coding Standards Skill

严谨规范的Python编码标准技能

Production-quality Python coding standards for writing clean, maintainable, modern Python code (versions 3.10-3.13).
适用于编写整洁、可维护的现代Python代码的生产级编码标准(支持版本3.10-3.13)。

When to Use This Skill

何时使用本技能

Auto-invoke when users ask about:
  • "make this pythonic" / "is this good python"
  • "type hints" / "type annotations" / "typing"
  • "LBYL vs EAFP" / "exception handling"
  • "pathlib vs os.path" / "path operations"
  • "CLI patterns" / "click usage"
  • "code review" / "improve this code"
  • Any Python code quality or standards question
Note: This skill is general Python standards, not Dagster-specific. Use
/dagster-best-practices
for Dagster patterns.
当用户询问以下内容时自动调用:
  • "让这段代码更符合Python风格" / "这段Python代码写得好吗"
  • "类型提示" / "类型注解" / "类型标注"
  • "LBYL vs EAFP" / "异常处理"
  • "pathlib vs os.path" / "路径操作"
  • "CLI模式" / "click使用方法"
  • "代码审查" / "优化这段代码"
  • 任何关于Python代码质量或编码标准的问题
注意:本技能是通用Python编码标准,不针对Dagster。若需Dagster相关模式,请使用
/dagster-best-practices

When to Use This Skill vs. Others

本技能与其他技能的适用场景对比

User NeedUse This SkillAlternative Skill
"make this pythonic"✅ Yes - Python standards
"is this good python"✅ Yes - code quality
"type hints"✅ Yes - typing guidance
"LBYL vs EAFP"✅ Yes - exception patterns
"pathlib vs os.path"✅ Yes - path handling
"best practices for dagster"❌ No
/dagster-best-practices
"implement X pipeline"❌ No
/dg
for implementation
"which integration to use"❌ No
/dagster-integrations
"CLI argument parsing"✅ Yes - CLI patterns
用户需求使用本技能替代技能
"让这段代码更符合Python风格"✅ 是 - Python编码标准
"这段Python代码写得好吗"✅ 是 - 代码质量检查
"类型提示"✅ 是 - 类型标注指导
"LBYL vs EAFP"✅ 是 - 异常处理模式
"pathlib vs os.path"✅ 是 - 路径处理规范
"Dagster最佳实践"❌ 否
/dagster-best-practices
"实现X流水线"❌ 否
/dg
用于实现开发
"使用哪个集成工具"❌ 否
/dagster-integrations
"CLI参数解析"✅ 是 - CLI模式规范

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):
  1. pyproject.toml
    - Look for
    requires-python
    field (e.g.,
    requires-python = ">=3.12"
    )
  2. setup.py
    or
    setup.cfg
    - Look for
    python_requires
  3. .python-version
    file - Contains version like
    3.12
    or
    3.12.0
  4. 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版本,按以下顺序检查:
  1. pyproject.toml
    - 查找
    requires-python
    字段(例如:
    requires-python = ">=3.12"
  2. setup.py
    setup.cfg
    - 查找
    python_requires
  3. .python-version
    文件 - 包含类似
    3.12
    3.12.0
    的版本号
  4. 若未找到版本指定,默认使用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
    references/cli-patterns.md
  • If task mentions "subprocess" -> Load subprocess patterns from core-standards
上述核心文件覆盖了80%以上的Python代码模式。仅当检测到特定模式时,才加载以下附加文件:
模式检测示例:
  • 若任务提及"click"或"CLI" -> 加载
    references/cli-patterns.md
  • 若任务提及"subprocess" -> 从核心标准中加载subprocess相关模式

Reference Documentation Structure

参考文档结构

The
references/
directory contains detailed guidance organized by topic:
references/
目录包含按主题组织的详细指导:

Core References

核心参考文档

  • core-standards.md
    - Essential standards (always loaded)
  • cli-patterns.md
    - Command-line interface patterns (click, argparse)
  • core-standards.md
    - 基础编码标准(始终加载)
  • cli-patterns.md
    - 命令行界面模式(click、argparse)

Version-Specific References (
references/versions/
)

版本特定参考文档(
references/versions/

  • python-3.10.md
    - Features available in Python 3.10+
  • python-3.11.md
    - Features available in Python 3.11+
  • python-3.12.md
    - Features available in Python 3.12+
  • python-3.13.md
    - Features available in Python 3.13+
  • python-3.10.md
    - Python 3.10及以上版本可用特性
  • python-3.11.md
    - Python 3.11及以上版本可用特性
  • python-3.12.md
    - Python 3.12及以上版本可用特性
  • python-3.13.md
    - Python 3.13及以上版本可用特性

Advanced Topics (
references/advanced/
)

进阶主题(
references/advanced/

  • exception-handling.md
    - LBYL patterns, error boundaries
  • interfaces.md
    - ABC and Protocol patterns
  • typing-advanced.md
    - Advanced typing patterns
  • api-design.md
    - API design principles
  • exception-handling.md
    - LBYL模式、错误边界
  • interfaces.md
    - ABC和Protocol模式
  • typing-advanced.md
    - 进阶类型标注模式
  • api-design.md
    - API设计原则

When to Read Each Reference Document

各参考文档的适用场景

references/advanced/exception-handling.md

references/advanced/exception-handling.md

Read when:
  • Writing try/except blocks
  • Wrapping third-party APIs that may raise
  • Seeing or writing
    from e
    or
    from None
  • Unsure if LBYL alternative exists
何时阅读
  • 编写try/except代码块时
  • 封装可能抛出异常的第三方API时
  • 看到或编写
    from e
    from None
  • 不确定是否有LBYL替代方案时

references/advanced/interfaces.md

references/advanced/interfaces.md

Read when:
  • Creating ABC or Protocol classes
  • Writing @abstractmethod decorators
  • Designing gateway layer interfaces
  • Choosing between ABC and Protocol
何时阅读
  • 创建ABC或Protocol类时
  • 编写@abstractmethod装饰器时
  • 设计网关层接口时
  • 在ABC和Protocol之间做选择时

references/advanced/typing-advanced.md

references/advanced/typing-advanced.md

Read when:
  • Using typing.cast()
  • Creating Literal type aliases
  • Narrowing types in conditional blocks
何时阅读
  • 使用typing.cast()时
  • 创建Literal类型别名时
  • 在条件块中缩小类型范围时

references/module-design.md

references/module-design.md

Read 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.md

Read 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.md

Read 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

如何使用本技能

  1. Core knowledge is loaded automatically (LBYL, pathlib, basic imports, anti-patterns)
  2. Version detection happens once - identify the minimum Python version and load the appropriate version file
  3. Reference documents are loaded on-demand based on the triggers above
  4. Additional patterns may require extra loading (CLI patterns, subprocess)
  5. Each file is self-contained with complete guidance for its domain
  1. 核心知识自动加载(LBYL、pathlib、基础导入、反模式)
  2. 版本检测仅执行一次 - 识别最低Python版本并加载对应的版本文件
  3. 参考文档根据上述触发条件按需加载
  4. 其他模式可能需要额外加载(如CLI模式、subprocess)
  5. 每个文件都是独立的,包含其领域的完整指导