Skip to content

Commit ae56202

Browse files
committed
lastgenre: Type alias GenresWithLabel
1 parent 47f6c96 commit ae56202

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎beetsplug/lastgenre/__init__.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
"""Genre hierarchy as list of paths from general to specific.
4343
Example: [['electronic', 'house'], ['electronic', 'techno']]"""
4444

45+
GenresWithLabel = tuple[list[str], str]
46+
"""A pair of (genre list, label) returned by a genre resolution stage.
47+
The label is used for logging and describes the source and filtering applied."""
48+
4549

4650
# Canonicalization tree processing.
4751

@@ -442,7 +446,7 @@ def _combine_resolve_and_log(
442446
return self._resolve_genres(combined, artist=artist)
443447

444448
@cached_property
445-
def fallback(self) -> tuple[list[str], str]:
449+
def fallback(self) -> GenresWithLabel:
446450
"""Return the configured fallback genre and label."""
447451
if fallback := self.config["fallback"].get():
448452
return [fallback], "fallback"
@@ -454,7 +458,7 @@ def _try_resolve_stage(
454458
keep_genres: list[str],
455459
new_genres: list[str],
456460
artist: str | None = None,
457-
) -> tuple[list[str], str] | None:
461+
) -> GenresWithLabel | None:
458462
"""Try to resolve genres for a given stage and log the result.
459463
460464
If any newly fetched genres and/or existing genres are resolved, return
@@ -474,7 +478,7 @@ def _try_resolve_stage(
474478

475479
def _try_resolve_existing_genres(
476480
self, obj: LibModel, genres: list[str]
477-
) -> tuple[list[str], str] | None:
481+
) -> GenresWithLabel | None:
478482
"""Handle existing genres when not forcing.
479483
480484
Clean up existing genres if enabled, or return them unchanged. Return
@@ -487,11 +491,11 @@ def _try_resolve_existing_genres(
487491
"cleanup", keep_genres, [], artist=self._artist_for_filter(obj)
488492
)
489493

490-
return genres, "keep any, no-force"
494+
return genres, "keep any, no-force" # type: ignore
491495

492496
def _try_resolve_original_fallback(
493497
self, obj: LibModel, genres: list[str], keep_genres: list[str]
494-
) -> tuple[list[str], str] | None:
498+
) -> GenresWithLabel | None:
495499
"""Attempt to fall back to existing original genres if configured.
496500
497501
``genres`` are the original unchanged values and are checked as-is
@@ -533,9 +537,7 @@ def _fetch_va_genres(self, album: Album) -> list[str]:
533537

534538
return []
535539

536-
def _fetch_artist_stage(
537-
self, obj: LibModel
538-
) -> tuple[str, list[str], str | None]:
540+
def _fetch_artist_stage(self, obj: LibModel) -> GenresWithLabel:
539541
"""Fetch artist genres for an Item or Album object.
540542
541543
Return a tuple of ``(stage_label, genres, stage_artist)``.
@@ -572,7 +574,7 @@ def _fetch_artist_stage(
572574

573575
return "most popular track", [], None
574576

575-
def _get_genre(self, obj: LibModel) -> tuple[list[str], str]:
577+
def _get_genre(self, obj: LibModel) -> GenresWithLabel:
576578
"""Get the final genre list for an Album or Item object.
577579
578580
`self.sources` specifies allowed genre sources. Starting with the first

0 commit comments

Comments
 (0)