Ditch convert_if_exists, just use option_fmap which I prefer

This commit is contained in:
Danielle McLean 2024-07-23 11:03:13 +10:00
parent fda799e32e
commit 1bb2032b9f
Signed by: 00dani
GPG key ID: 6854781A0488421C
2 changed files with 3 additions and 10 deletions

View file

@ -11,7 +11,7 @@ from ..config.model import MpdConfig
from ..player import Player
from ..song import Artwork, PlaybackState, Song, to_artwork, to_brainz
from ..song_receiver import Receiver
from ..tools.types import convert_if_exists, un_maybe_plural
from ..tools.types import option_fmap, un_maybe_plural
from .artwork_cache import MpdArtworkCache
from .types import CurrentSongResponse, StatusResponse
@ -30,8 +30,8 @@ def mpd_current_to_song(
album_artist=un_maybe_plural(current.get("albumartist")),
composer=un_maybe_plural(current.get("composer")),
genre=un_maybe_plural(current.get("genre")),
track=convert_if_exists(current.get("track"), int),
disc=convert_if_exists(current.get("disc"), int),
track=option_fmap(int, current.get("track")),
disc=option_fmap(int, current.get("disc")),
duration=float(status["duration"]),
elapsed=float(status["elapsed"]),
musicbrainz=to_brainz(current),

View file

@ -5,7 +5,6 @@ __all__ = (
"AnyExceptList",
"MaybePlural",
"option_fmap",
"convert_if_exists",
"un_maybe_plural",
)
@ -45,12 +44,6 @@ def option_fmap(f: Callable[[U], V], value: U | None) -> V | None:
return f(value)
def convert_if_exists(value: str | None, converter: Callable[[str], U]) -> U | None:
if value is None:
return None
return converter(value)
T = TypeVar("T", bound=AnyExceptList)
MaybePlural: TypeAlias = list[T] | T