← ClaudeAtlas

python-patternslisted

Use for Python in an existing project when choosing idiomatic typing, Pydantic models, error handling, asyncio, concurrency, or async design.
lawzava/megapowers · ★ 4 · AI & Automation · score 73
Install: claude install-skill lawzava/megapowers
# Python Patterns > **Measured:** current frontier *and* small Claude models already write the > common async/DB mechanics here (asyncio pools and queue termination, shared > in-memory SQLite) correctly single-shot without this skill — a controlled > study found zero correctness headroom, 184/184 passing in both arms (the > repo's `evals/RESULTS.md` §2). Reach for this skill for idiomatic typing and > error-shaping *choices*, as a review checklist, or when driving weaker > models; not because a current model would otherwise hang a consumer loop. Idioms for correct, readable Python. Each is a default, not a law. ## Typing - Type public functions fully; let inference handle locals. Run the type checker in strict mode (see greenfield-python-stack) — an untyped boundary hides bugs. - Prefer precise types: `Sequence`/`Mapping` for read-only params, `list`/`dict` for what you own and mutate. Use `X | None` (not bare `Optional` guesswork) and handle the `None` branch. - Model closed sets with a discriminated union (`Literal` tag + `match`) or an `Enum`, so the type checker forces you to handle every case. ## Data - `@dataclass(frozen=True, slots=True)` for internal value objects; **pydantic** models at the boundaries (request/response/config) where you need validation and parsing. - Don't hand-roll validation you can declare on a pydantic model. ## Errors - Raise specific exceptions; don't `except Exception:` and swallow. Catch the narrowest type, add context, an