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.

1.6 KB
Raw Blame
# Flags function return annotations that are tuples where callers can silently
# swap same-typed elements (e.g. `tuple[int, int]` for `(start, end)`) or must
# read 3+ elements positionally. Partial enforcement of the frozen-dataclass
# convention in .agents/code-style.md.
#
# See: https://github.com/PostHog/posthog/pull/75818 for context
rules:
    - id: tuple-return-prefer-dataclass
      patterns:
          - pattern-either:
                - pattern: |
                      def $F(...) -> $RET:
                          ...
                - pattern: |
                      async def $F(...) -> $RET:
                          ...
          - metavariable-pattern:
                metavariable: $RET
                patterns:
                    - pattern-either:
                          - pattern: tuple[$T, $T]
                          - pattern: Tuple[$T, $T]
                          - pattern: tuple[$A, $B, $C, ...]
                          - pattern: Tuple[$A, $B, $C, ...]
          - focus-metavariable: $RET
      message: |
          This returns a tuple whose elements can be silently swapped at the
          call site (two share a type) or must be read positionally (3+
          elements). Prefer a frozen dataclass with named fields: `@frozen`
          from `posthog.dataclasses` (frozen, kw_only, slots by default). See
          the Python bullets in .agents/code-style.md.
          Pre-existing findings are grandfathered; only newly-introduced ones
          block CI.
      languages: [python]
      severity: WARNING
      metadata:
          category: maintainability
          subcategory: audit
          confidence: HIGH