From bbc82b8cc87e80839fc74b8d6a7d754e16c27b18 Mon Sep 17 00:00:00 2001 From: J0J0 Todos Date: Mon, 9 Mar 2026 07:30:15 +0100 Subject: [PATCH] lastgenre: Dedup fallback handling in _get_genre and fix fallback types --- beetsplug/lastgenre/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index adee38e7b..6d5c90c40 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -460,6 +460,12 @@ class LastGenrePlugin(plugins.BeetsPlugin): and the whitelist feature was disabled. """ + def _fallback_stage() -> tuple[list[str], str]: + """Return the fallback genre and label.""" + if fallback := self.config["fallback"].get(): + return [fallback], "fallback" + return [], "fallback unconfigured" + def _try_resolve_stage( stage_label: str, keep_genres: list[str], @@ -496,8 +502,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): ): return result - # Return fallback string (None if not set). - return self.config["fallback"].get(), "fallback" + return _fallback_stage() # If cleanup_existing is not set, the pre-populated tags are # returned as-is. @@ -587,7 +592,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): return result # Nothing found, leave original if configured and valid. - if genres and self.config["keep_existing"].get(bool): + if genres and self.config["keep_existing"].get(): if isinstance(obj, library.Item): # For track items, use track artist (important for compilations). artist = getattr(obj, "artist", None) @@ -605,12 +610,7 @@ class LastGenrePlugin(plugins.BeetsPlugin): ): return result - # Return fallback as a list. - if fallback := self.config["fallback"].get(): - return [fallback], "fallback" - - # No fallback configured. - return [], "fallback unconfigured" + return _fallback_stage() # Beets plugin hooks and CLI.