Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing: Add mypy for theaudiodb #1522

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions music_assistant/server/models/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import TYPE_CHECKING, Any

from music_assistant.constants import CONF_LOG_LEVEL, MASS_LOGGER_NAME
from music_assistant.server.helpers.throttle_retry import ThrottlerManager

if TYPE_CHECKING:
from zeroconf import ServiceStateChange
Expand All @@ -21,8 +20,6 @@
class Provider:
"""Base representation of a Provider implementation within Music Assistant."""

throttler: ThrottlerManager # optional throttler

def __init__(
self, mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
) -> None:
Expand Down
15 changes: 8 additions & 7 deletions music_assistant/server/providers/theaudiodb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from json import JSONDecodeError
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, cast

import aiohttp.client_exceptions
from asyncio_throttle import Throttler
Expand All @@ -19,9 +19,10 @@
MediaItemLink,
MediaItemMetadata,
Track,
UniqueList,
)
from music_assistant.server.controllers.cache import use_cache
from music_assistant.server.helpers.app_vars import app_var # pylint: disable=no-name-in-module
from music_assistant.server.helpers.app_vars import app_var # type: ignore[attr-defined]
from music_assistant.server.helpers.compare import compare_strings
from music_assistant.server.models.metadata_provider import MetadataProvider

Expand Down Expand Up @@ -199,7 +200,7 @@ def __parse_artist(self, artist_obj: dict[str, Any]) -> MediaItemMetadata:
else:
metadata.description = artist_obj.get("strBiographyEN")
# images
metadata.images = []
metadata.images = UniqueList()
for key, img_type in IMG_MAPPING.items():
for postfix in ("", "2", "3", "4", "5", "6", "7", "8", "9", "10"):
if img := artist_obj.get(f"{key}{postfix}"):
Expand Down Expand Up @@ -245,7 +246,7 @@ def __parse_album(self, album_obj: dict[str, Any]) -> MediaItemMetadata:
metadata.description = album_obj.get("strDescriptionEN")
metadata.review = album_obj.get("strReview")
# images
metadata.images = []
metadata.images = UniqueList()
for key, img_type in IMG_MAPPING.items():
for postfix in ("", "2", "3", "4", "5", "6", "7", "8", "9", "10"):
if img := album_obj.get(f"{key}{postfix}"):
Expand Down Expand Up @@ -279,7 +280,7 @@ def __parse_track(self, track_obj: dict[str, Any]) -> MediaItemMetadata:
else:
metadata.description = track_obj.get("strDescriptionEN")
# images
metadata.images = []
metadata.images = UniqueList([])
for key, img_type in IMG_MAPPING.items():
for postfix in ("", "2", "3", "4", "5", "6", "7", "8", "9", "10"):
if img := track_obj.get(f"{key}{postfix}"):
Expand All @@ -296,15 +297,15 @@ def __parse_track(self, track_obj: dict[str, Any]) -> MediaItemMetadata:
return metadata

@use_cache(86400 * 30)
async def _get_data(self, endpoint, **kwargs) -> dict | None:
async def _get_data(self, endpoint: str, **kwargs: Any) -> dict[str, Any] | None:
"""Get data from api."""
url = f"https://theaudiodb.com/api/v1/json/{app_var(3)}/{endpoint}"
async with (
self.throttler,
self.mass.http_session.get(url, params=kwargs, ssl=False) as response,
):
try:
result = await response.json()
result = cast(dict[str, Any], await response.json())
except (
aiohttp.client_exceptions.ContentTypeError,
JSONDecodeError,
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
packages=tests,music_assistant.client,music_assistant.common,music_assistant.server.providers.builtin,music_assistant.server.providers.filesystem_local,music_assistant.server.providers.filesystem_smb,music_assistant.server.providers.fully_kiosk,music_assistant.server.providers.jellyfin,music_assistant.server.providers.plex,music_assistant.server.providers.radiobrowser,music_assistant.server.providers.test
packages=tests,music_assistant.client,music_assistant.common,music_assistant.server.providers.builtin,music_assistant.server.providers.filesystem_local,music_assistant.server.providers.filesystem_smb,music_assistant.server.providers.fully_kiosk,music_assistant.server.providers.jellyfin,music_assistant.server.providers.plex,music_assistant.server.providers.radiobrowser,music_assistant.server.providers.test,music_assistant.server.providers.theaudiodb