pythonlisted
Install: claude install-skill dean0x/devflow
# Python Patterns
## Iron Law
> **EXPLICIT IS BETTER THAN IMPLICIT** [3]
>
> Type-hint every function signature. Name every exception. Use dataclasses over raw
> dicts. Python's flexibility is a strength only when boundaries are explicit.
## When This Skill Activates
Working with Python codebases, designing typed APIs, modeling data with dataclasses
or Pydantic, implementing async code, structuring Python packages.
---
## Type Safety
### Type Hint Everything [4][17][18]
```python
# BAD: def process(data, config): ...
def process(data: list[dict[str, Any]], config: AppConfig) -> ProcessResult: ...
```
Dropbox's 4M-line mypy migration eliminated entire bug classes [18]. Use
`from __future__ import annotations` for forward references [22].
### Protocols for Structural Typing [5][1]
```python
from typing import Protocol
class Repository(Protocol):
def find_by_id(self, id: str) -> User | None: ...
def save(self, entity: User) -> User: ...
```
PEP 544 formalizes duck typing as "static duck typing" — no `implements`
required [5]. Any class with matching methods satisfies the Protocol [1].
### Strict Optional Handling [4][23]
PEP 604 `X | Y` syntax replaces verbose `Optional[X]` [23]:
```python
def get_name(user: User | None) -> str:
return "Anonymous" if user is None else user.name
```
---
## Error Handling [2][8][9]
```python
class AppError(Exception): ...
class NotFoundError(AppError):
def __init__(self, entity: str, id: str) -> None:
su