Skip to content

Type the media-buy status_filter/context parameters instead of bare Any #1707

Description

@numarasSigmaSoftware

Raised as inline review feedback on #1544 and never tracked; verified still open at f94e72f92 and confirmed pre-existing (the same lines exist on main, so no PR introduced it).

Problem

status_filter is annotated Any at four sites where a concrete type exists:

  • src/routes/api_v1.py:130 and :148 (context: Any on the same signatures)
  • src/core/schemas/_base.py:2856
  • src/core/tools/media_buy_delivery.py:867

The concrete type is MediaBuyStatus | list[MediaBuyStatus] | None — the parameter accepts a single status or a list of them, and the values are drawn from the existing MediaBuyStatus vocabulary. Annotating it Any means neither mypy nor the IDE catches a caller passing an unmodelled status string, which is exactly the class of bug the persisted-status vocabulary work has been tightening elsewhere.

context: Any on the same two api_v1.py signatures has a concrete type available as well.

Why this is not already covered

The repo has ratcheting baselines for typing debt (.mypy-untyped-defs-baseline, .type-ignore-baseline), but neither covers an explicit Any annotation on a typed def — those ratchets track untyped definitions and type: ignore comments respectively. So these sites are invisible to the existing ratchets and will not be picked up by them over time.

Fix

Replace the Any annotations with the concrete union, fix any call sites the narrowing surfaces, and run mypy over the four files. If a site genuinely needs to stay permissive, narrow it to the widest honest type rather than Any and note why inline.

Context

Surfaced by review feedback on #1544 ("status_filter: Any (and context: Any below) where concrete types exist"); filed separately because it is pre-existing and out of that PR's scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions