Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(agents): prefer frozen dataclasses over big or swappable tuples (#75818)

Arno Hillen96b7fa74115d
diff --git a/AGENTS.md b/AGENTS.md
index c663ef9e9c41..f2f79f42cc40 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -173,6 +173,7 @@ See [.agents/security.md](.agents/security.md) for security guidelines — least
- Python: Write as if mypy `--strict` is enabled — annotate all function signatures (arguments + return types), avoid `Any`, use `TYPE_CHECKING` imports for type-only references. When a change is type-risky, run mypy the way CI does — `uv run mypy --cache-fine-grained .`, repo-wide, never a file subset (it follows imports, so a subset misses reverse-dependency breakage); `hogli ci:preflight` reminds you, and CI blocks on the same command. The config isn't fully strict yet, but new code should be
- Python imports: keep imports at module level — not inside functions, methods, or conditionals. Inline imports hide dependencies from static analysis, slow hot paths with repeated lookups, and mask circular-import problems instead of fixing them; ruff's `PLC0415` enforces this. Defer an import only to (1) break a true unavoidable circular import (fix the structure first if you can), (2) reference types under `TYPE_CHECKING`, or (3) keep a heavy/optional dependency off the import path so it loads only when its code runs. For (3), add a justified `# noqa: PLC0415` on the import line (e.g. `# noqa: PLC0415 — keeps the heavy dep off the import path`) — never blanket-suppress the rule
+- Python: prefer a frozen dataclass (`@dataclass(frozen=True)`) over a tuple when returning or passing multiple values, in two cases: (1) two or more elements share a type, so callers can silently swap them (e.g. `(start, end)`, `(width, height)`); add `kw_only=True` here so construction is keyword-only and a swap is impossible at the call site too; (2) the tuple is big (roughly 3+ elements), where positional access hurts readability. Named fields make the code easier to read and, combined with keyword-only construction, make swapped-value bugs impossible. Small tuples with unambiguous, differently typed elements are fine as-is
- Frontend: for any frontend work — the main app (`frontend/src/`) **or** a product frontend (`products/*/frontend/`) — follow [frontend/src/AGENTS.md](frontend/src/AGENTS.md): reuse existing Lemon/quill components instead of hand-rolling tables/badges/labels, import generated `*Api` types instead of handwriting them, and run typecheck/typegen at the right moments. Product frontends share the same components and generated types, so the same rules apply there
- Frontend: TypeScript required, explicit return types
- Frontend: If there is a kea logic file, write all business logic there, avoid React hooks at all costs.