Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive typing for MusicBrainz API payloads through TypedDict models, refactors parsing logic into smaller helpers, normalizes API responses at the boundary (converting dashes to underscores and grouping relations), and replaces hand-written test dictionaries with factory-based data generation.
Changes:
- Introduced typed domain models (
Release,Recording,Medium, etc.) inbeetsplug/_utils/musicbrainz.py - Normalized MusicBrainz API responses by converting dashed keys to underscores and grouping relations
- Refactored parsing into focused helper methods (
_parse_artist_credits,_parse_release_group, etc.)
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
test/rsrc/mbpseudo/pseudo_release.json |
Updated test fixture to use underscored keys matching normalized payload format |
test/rsrc/mbpseudo/official_release.json |
Updated test fixture to use underscored keys matching normalized payload format |
test/plugins/utils/test_musicbrainz.py |
Renamed test from test_group_relations to test_normalize_data reflecting the renamed internal method |
test/plugins/test_musicbrainz.py |
Replaced manual test data construction with factory-based approach and updated assertions to match factory defaults |
test/plugins/test_mbpseudo.py |
Updated references from dashed keys to underscored keys |
test/plugins/factories/musicbrainz.py |
Added factory classes for generating typed MusicBrainz test data |
setup.cfg |
Enabled strict mypy checking for musicbrainz-related modules |
pyproject.toml |
Added pytest-factoryboy test dependency |
beetsplug/musicbrainz.py |
Refactored parsing logic into typed helper methods and updated to consume normalized payloads |
beetsplug/mbpseudo.py |
Updated to use typed Release structures and underscored keys |
beetsplug/_utils/musicbrainz.py |
Added comprehensive TypedDict models and renamed/enhanced _group_relations to _normalize_data |
Comments suppressed due to low confidence (2)
beetsplug/_utils/musicbrainz.py:1
- The length checks are redundant. If
map(int, date_str.split('-'))produces fewer than three parts, accessingparts[1]orparts[2]will raise anIndexErrorrather than returningNone. The current implementation doesn't actually prevent the error. Consider usingparts[i] if i < len(parts) else Noneor a more concise approach like padding the list.
"""Helpers for communicating with the MusicBrainz webservice.
beetsplug/musicbrainz.py:1
- Corrected spelling of 'attribute_credits' to 'attribute_values' to match the actual field name in ArtistRelation TypedDict.
# This file is part of beets.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6329 +/- ##
==========================================
+ Coverage 70.19% 70.51% +0.32%
==========================================
Files 147 147
Lines 18698 18904 +206
Branches 3046 3046
==========================================
+ Hits 13125 13331 +206
Misses 4930 4930
Partials 643 643
🚀 New features to boost your workflow:
|
|
I also did a similar sort of refactoring recently, and this is what I ended up with: https://github.com/prTopi/beets-vocadb/tree/eeb047027a54d331cfe1d54bc1126046c5382a9b/src/beetsplug/_utils/vocadb/vocadb_api_client Feel free to take inpiration! Here are some suggestions:
|
db30e6b to
f867887
Compare
a6a3aa5 to
ec1ce1d
Compare
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
7d0a0e5 to
fa3e5ac
Compare
I don't see any benefit for doing so (this may actually increase verbosity because of shorter line lengths and reformatting). Sometimes they should be defined outside the
Again, I don't see any benefit for this - these are just static definitions without any functionality attached to them.
These definitions belong to the |
Add full type coverage to the MusicBrainz plugin
This PR introduces complete static typing for
beetsplug/musicbrainz.py,beetsplug/mbpseudo.py, andbeetsplug/_utils/musicbrainz.py, and enforces it viamypystrict mode.Key changes
New
TypedDictschema inbeetsplug/_utils/musicbrainz.pyA comprehensive set of
TypedDictclasses 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 opaqueJSONDict.Key normalization: dash-to-underscore
The internal
_normalize_datamethod (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 theTypedDictdefinitions to use clean attribute names. All downstream field accesses, test fixtures, and JSON test resources are updated accordingly.mypystrict mode enabled for the three affected modules viasetup.cfg.Impact
_normalize_data, so callers never see raw hyphenated keys.