2828
2929 from beets .logging import Logger
3030
31+ from .types import CanonTree , Whitelist
32+
3133
3234class DataFileLoader :
3335 """Loads genre-related data files for the lastgenre plugin."""
@@ -36,8 +38,8 @@ def __init__(
3638 self ,
3739 log : Logger ,
3840 plugin_dir : Path ,
39- whitelist : set [ str ] ,
40- c14n_branches : list [ list [ str ]] ,
41+ whitelist : Whitelist ,
42+ c14n_branches : CanonTree ,
4143 canonicalize : bool ,
4244 ):
4345 """Initialize with pre-loaded data.
@@ -83,7 +85,7 @@ def from_config(
8385 @staticmethod
8486 def _load_whitelist (
8587 log : Logger , config_value : str | bool | None , default_path : str
86- ) -> set [ str ] :
88+ ) -> Whitelist :
8789 """Load the whitelist from a text file.
8890
8991 Returns set of valid genre names (lowercase).
@@ -107,12 +109,12 @@ def _load_tree(
107109 config_value : str | bool | None ,
108110 default_path : str ,
109111 prefer_specific : bool ,
110- ) -> tuple [list [ list [ str ]] , bool ]:
112+ ) -> tuple [CanonTree , bool ]:
111113 """Load the canonicalization tree from a YAML file.
112114
113115 Returns tuple of (branches, canonicalize_enabled).
114116 """
115- c14n_branches : list [ list [ str ]] = []
117+ c14n_branches : CanonTree = []
116118 c14n_filename = config_value
117119 canonicalize = c14n_filename is not False
118120 # Default tree
@@ -133,9 +135,24 @@ def _load_tree(
133135 def flatten_tree (
134136 elem : dict [str , Any ] | list [Any ] | str ,
135137 path : list [str ],
136- branches : list [ list [ str ]] ,
138+ branches : CanonTree ,
137139 ) -> None :
138- """Flatten nested lists/dictionaries into lists of strings (branches)."""
140+ """Flatten nested YAML structure into genre hierarchy branches.
141+
142+ Recursively converts nested dicts/lists from YAML into a flat list
143+ of genre paths, where each path goes from general to specific genre.
144+
145+ Args:
146+ elem: The YAML element to process (dict, list, or string leaf).
147+ path: Current path from root to this element (used in recursion).
148+ branches: OUTPUT PARAMETER - Empty list that will be populated
149+ with genre paths. Gets mutated by this method.
150+
151+ Example:
152+ branches = []
153+ flatten_tree({'rock': ['indie', 'punk']}, [], branches)
154+ # branches is now: [['rock', 'indie'], ['rock', 'punk']]
155+ """
139156 if not path :
140157 path = []
141158
0 commit comments