Python style

From jpoutrin/product-forge · View interactive version

Python style is an AI agent skill from the GitHub repository jpoutrin/product-forge. Python coding style enforcement (PEP standards, type hints, docstrings, modern patterns). Auto-loads when writing or reviewing Python code.

How to use this skill

Skill file

Python Style Best Practices Skill

This skill automatically activates when writing Python code to ensure consistency with PEP standards, type hints, and modern Python idioms.

Core Standards

Naming Conventions

# Classes: PascalCase
class UserAccount:
    pass

# Functions/variables: snake_case
def calculate_total():
    user_name = "john"

# Constants: SCREAMING_SNAKE_CASE
MAX_RETRY_COUNT = 3

# Private: single underscore prefix
def _internal_helper():
    pass

Type Hints (Python 3.10+)

# Use built-in generics
def process(items: list[str]) -> dict[str, int]:
    pass

# Use | for Optional/Union
def find_user(id: str) -> User | None:
    pass

# TypedDict for structured dicts
class UserData(TypedDict):
    id: str
    name: str

Function Length Guidelines

Anti-Patterns to Avoid

Merge-Friendly Patterns (for Parallel Development)

When multiple agents modify the same module, follow these patterns to enable automatic merge resolution by semantic merge tools (mergiraf).

Always Run Ruff Before Commit

uv run ruff format .
uv run ruff check --fix .

This ensures imports are consistently ordered, enabling clean merges.

`__all__` Must Be Alphabetical

Enable RUF022 in ruff to enforce this automatically:

[tool.ruff.lint]
select = [
    # ... other rules
    "RUF022", # unsorted-dunder-all (enforces alphabetical __all__)
]
# CORRECT - alphabetical, one per line, no comments
__all__ = [
    "ACLFilterSpec",
    "Chunk",
    "ChunkerInterface",
    "Document",
    "QueryACLContext",
    "Visibility",
]

# WRONG - grouped by category (causes merge conflicts)
__all__ = [
    # Types
    "Chunk",
    "Document",
    # Interfaces
    "ChunkerInterface",
]

No Comments Inside Lists

Comments inside __all__, import groups, or other lists break deterministic ordering and cause merge conflicts. Keep comments outside:

# ACL and schema types exported for public API
__all__ = [
    "ACLFilterSpec",
    "Chunk",
    "Document",
]

When Adding to Shared Files (`__init__.py`, etc.)

  1. Add new exports in alphabetical position
  2. Never reorder existing exports
  3. Run ruff format immediately after changes
  4. Avoid adding section comments

Why This Matters

Semantic merge tools like mergiraf can automatically resolve conflicts when:

Without these patterns, parallel agents adding exports to the same __init__.py will create conflicts requiring manual resolution.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.