Skip to content

Commit

Permalink
refactor(models): better typing for search response results
Browse files Browse the repository at this point in the history
  • Loading branch information
bendikrb committed Oct 30, 2024
1 parent cdb563e commit 63e116e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions nrk_psapi/models/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dataclasses import dataclass, field
from datetime import datetime # noqa: TCH003
from typing import Literal
from typing import Generic, Literal, TypeVar

from mashumaro import field_options
from mashumaro.config import BaseConfig
Expand Down Expand Up @@ -314,24 +314,27 @@ class SearchResponseResultSeriesEpisode(SearchResponseResultEpisode):
type = SearchResultType.SERIES_EPISODE


ResultT = TypeVar("ResultT", bound=SearchResponseResult)


@dataclass
class SearchResponseResultsResult(BaseDataClassORJSONMixin):
class SearchResponseResultsResult(BaseDataClassORJSONMixin, Generic[ResultT]):
"""Represents the result object in the results array in the main response object from the podcast search API."""

results: list[SearchResponseResult]
results: list[ResultT]
links: SearchResultLink | None = None


@dataclass
class SearchResponseResults(BaseDataClassORJSONMixin):
"""Represents the results object in the main response object from the podcast search API."""

channels: SearchResponseResultsResult
categories: SearchResponseResultsResult
series: SearchResponseResultsResult
episodes: SearchResponseResultsResult
contents: SearchResponseResultsResult
contributors: SearchResponseResultsResult
channels: SearchResponseResultsResult[SearchResponseResultChannel]
categories: SearchResponseResultsResult[SearchResponseResultCategory]
series: SearchResponseResultsResult[SearchResponseResultSeries | SearchResponseResultPodcast]
episodes: SearchResponseResultsResult[SearchResponseResultEpisode]
contents: SearchResponseResultsResult[SearchResponseResult]
contributors: SearchResponseResultsResult[SearchResponseResult]


@dataclass
Expand Down

0 comments on commit 63e116e

Please sign in to comment.