Commit ff9f93e
authored
Type musicbrainz (#6329)
## Add full type coverage to the MusicBrainz plugin
This PR introduces complete static typing for
`beetsplug/musicbrainz.py`, `beetsplug/mbpseudo.py`, and
`beetsplug/_utils/musicbrainz.py`, and enforces it via `mypy` strict
mode.
### Key changes
**New `TypedDict` schema in `beetsplug/_utils/musicbrainz.py`**
A comprehensive set of `TypedDict` classes now models the full
MusicBrainz API response surface — `Release`, `Recording`, `Track`,
`ReleaseGroup`, `Artist`, `ArtistCredit`, `Work`, and all relation
types. Public API methods (`get_release`, `get_recording`, etc.) now
return these typed shapes instead of the opaque `JSONDict`.
**Key normalization: dash-to-underscore**
The internal `_normalize_data` method (previously `_group_relations`)
now also converts all hyphenated keys (e.g. `artist-credit`,
`release-group`, `sort-name`) to underscored equivalents (e.g.
`artist_credit`, `release_group`, `sort_name`) at parse time. This makes
the data structure Python-idiomatic and is what allows the `TypedDict`
definitions to use clean attribute names. All downstream field accesses,
test fixtures, and JSON test resources are updated accordingly.
**`mypy` strict mode enabled** for the three affected modules via
`setup.cfg`.
### Impact
- No behaviour change for end users — this is purely an internal
refactor.
- Code reading the MusicBrainz response now has IDE completion and
type-checking support.
- The normalization boundary is clearly established at
`_normalize_data`, so callers never see raw hyphenated keys.
- Test fixtures and resource JSON files are updated to match the new
normalized shape.14 files changed
Lines changed: 1269 additions & 752 deletions
File tree
- beetsplug
- _utils
- docs
- test
- plugins
- utils
- rsrc/mbpseudo
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
133 | 138 | | |
134 | 139 | | |
135 | 140 | | |
136 | | - | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
161 | 166 | | |
162 | 167 | | |
163 | 168 | | |
164 | | - | |
| 169 | + | |
165 | 170 | | |
166 | 171 | | |
167 | 172 | | |
168 | 173 | | |
169 | 174 | | |
170 | 175 | | |
171 | | - | |
| 176 | + | |
172 | 177 | | |
173 | 178 | | |
174 | 179 | | |
175 | 180 | | |
176 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
177 | 184 | | |
178 | 185 | | |
179 | | - | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
186 | 193 | | |
187 | | - | |
| 194 | + | |
188 | 195 | | |
189 | 196 | | |
190 | 197 | | |
| |||
206 | 213 | | |
207 | 214 | | |
208 | 215 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 216 | + | |
212 | 217 | | |
213 | 218 | | |
214 | 219 | | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
222 | 227 | | |
223 | 228 | | |
224 | 229 | | |
| |||
0 commit comments