Skip to content

Commit

Permalink
chore: mypy for musicbrainz
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k committed Jan 13, 2025
1 parent 3c09a10 commit 586950c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
35 changes: 18 additions & 17 deletions music_assistant/providers/musicbrainz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
from contextlib import suppress
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, TypeVar, cast

from mashumaro import DataClassDictMixin
from mashumaro.exceptions import MissingField
Expand All @@ -27,13 +27,13 @@
from music_assistant_models.media_items import Album, Track
from music_assistant_models.provider import ProviderManifest

from music_assistant import MusicAssistant
from music_assistant.mass import MusicAssistant
from music_assistant.models import ProviderInstanceType


LUCENE_SPECIAL = r'([+\-&|!(){}\[\]\^"~*?:\\\/])'

SUPPORTED_FEATURES = set()
_T = TypeVar("_T")


async def setup(
Expand All @@ -60,18 +60,19 @@ async def get_config_entries(
return () # we do not have any config entries (yet)


def replace_hyphens(data: dict[str, Any]) -> dict[str, Any]:
def replace_hyphens(data: _T) -> _T:
"""Change all hyphens to underscores."""
new_values = {}
for key, value in data.items():
new_key = key.replace("-", "_")
if isinstance(value, dict):
if isinstance(data, dict):
new_values = {}
for key, value in data.items():
new_key = key.replace("-", "_")
new_values[new_key] = replace_hyphens(value)
elif isinstance(value, list):
new_values[new_key] = [replace_hyphens(x) if isinstance(x, dict) else x for x in value]
else:
new_values[new_key] = value
return new_values
return cast(_T, new_values)

if isinstance(data, list):
return cast(_T, [replace_hyphens(x) if isinstance(x, dict) else x for x in value])

return data


@dataclass
Expand Down Expand Up @@ -202,7 +203,7 @@ async def handle_async_init(self) -> None:
@property
def supported_features(self) -> set[ProviderFeature]:
"""Return the features supported by this Provider."""
return SUPPORTED_FEATURES
return set()

async def search(
self, artistname: str, albumname: str, trackname: str, trackversion: str | None = None
Expand Down Expand Up @@ -337,7 +338,7 @@ async def get_artist_details_by_album(
MusicBrainzArtist object that is returned does not contain the optional data.
"""
result = None
result: MusicBrainzRelease | MusicBrainzReleaseGroup | None = None
if mb_id := ref_album.get_external_id(ExternalID.MB_RELEASEGROUP):
with suppress(InvalidDataError):
result = await self.get_releasegroup_details(mb_id)
Expand Down Expand Up @@ -398,13 +399,13 @@ async def get_artist_details_by_resource_url(

@use_cache(86400 * 30)
@throttle_with_retries
async def get_data(self, endpoint: str, **kwargs: dict[str, Any]) -> Any:
async def get_data(self, endpoint: str, **kwargs: str) -> Any:
"""Get data from api."""
url = f"http://musicbrainz.org/ws/2/{endpoint}"
headers = {
"User-Agent": f"Music Assistant/{self.mass.version} (https://music-assistant.io)"
}
kwargs["fmt"] = "json" # type: ignore[assignment]
kwargs["fmt"] = "json"
async with (
self.mass.http_session.get(url, headers=headers, params=kwargs) as response,
):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ exclude = [
'^music_assistant/providers/fanarttv/.*$',
'^music_assistant/providers/hass/.*$',
'^music_assistant/providers/hass_players/.*$',
'^music_assistant/providers/musicbrainz/.*$',
'^music_assistant/providers/player_group/.*$',
'^music_assistant/providers/podcastfeed/.*$',
'^music_assistant/providers/qobuz/.*$',
Expand Down

0 comments on commit 586950c

Please sign in to comment.