Conversation
Delegate the responsibility of getting relevant model fields to the client by declaring the genre fetching spec on the class.
This issue has been resolved in 2014.
|
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
PR make lastgenre Last.fm client API smaller. Instead of 3 fetch funcs, now one fetch(kind, obj) dispatch table, and plugin call sites updated to use it.
Changes:
- Add
LastFmClient.FETCH_METHODSregistry and newfetch(kind, obj)dispatcher. - Inline old tag parsing into
fetch_genresand remove old per-entity fetch methods. - Update plugin + tests to use new fetch API and simpler mocking.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| beetsplug/lastgenre/client.py | Add unified fetch dispatch + simplify tag fetch/filter path |
| beetsplug/lastgenre/init.py | Switch genre resolution stages to call client.fetch(kind, obj) |
| test/plugins/test_lastgenre.py | Update tests to new API + monkeypatch LastFmClient.fetch |
| for albumartist in obj.albumartists: | ||
| self._log.extra_debug( | ||
| 'Fetching artist genre for "{}"', | ||
| albumartist, | ||
| ) | ||
| new_genres += self.client.fetch_artist_genre( | ||
| albumartist | ||
| ) | ||
| new_genres += self.client.fetch("album_artist", obj) | ||
| if new_genres: |
There was a problem hiding this comment.
grug see bug. in multi-valued album artist loop, code log each albumartist but call self.client.fetch("album_artist", obj) each time. fetch arg_fn use obj.albumartist, so loop repeat same lookup and ignore per-artist value. need pass albumartist into client lookup (maybe new kind that takes explicit string, or let fetch accept override args) so each artist actually fetched.
| """Core genre identification routine. | ||
| """Return genres for a pylast entity. | ||
|
|
||
| Given a pylast entity (album or track), return a list of |
There was a problem hiding this comment.
grug confused docstring. fetch_genres now take Album/Artist/Track, but doc text still say "album or track". update doc so match real types and behavior.
| Given a pylast entity (album or track), return a list of | |
| Given a pylast entity (album, artist, or track), return a list of |
| "track", LASTFM.get_track, trackartist, tracktitle | ||
| ) | ||
| def fetch(self, kind: str, obj: LibModel) -> list[str]: | ||
| """Fetch fetcher for Last.fm genres.""" |
There was a problem hiding this comment.
grug spot typo in docstring: "Fetch fetcher". should be clear what method do (fetch genres for kind) so reader not trip.
| """Fetch fetcher for Last.fm genres.""" | |
| """Fetch Last.fm genres for the specified kind.""" |
| assert res == ["pop", "rap"] | ||
| res = plugin.client._tags_for(MockPylastObj(), min_weight=50) | ||
|
|
||
| plugin.client._min_weight = 50 |
There was a problem hiding this comment.
grug not like test reach into private _min_weight. test will break if client internals change. better make client with min_weight=50 (new plugin instance / re-run setup with config) or expose small public way to set min_weight for test.
| plugin.client._min_weight = 50 | |
| self.config["lastgenre"]["min_weight"] = 50 | |
| plugin = lastgenre.LastGenrePlugin() | |
| plugin.setup() |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6495 +/- ##
=======================================
Coverage 70.06% 70.06%
=======================================
Files 147 147
Lines 18562 18554 -8
Branches 3026 3025 -1
=======================================
- Hits 13005 13000 -5
+ Misses 4924 4921 -3
Partials 633 633
🚀 New features to boost your workflow:
|
Consolidate Last.fm genre fetching into a single
fetchmethodThis PR simplifies the
lastgenreclient API by replacing three separate fetch methods (fetch_track_genre,fetch_album_genre,fetch_artist_genre) with a single unifiedfetch(kind, obj)method.What changed
client.py:FETCH_METHODSregistry (ClassVardict) mapping fetch "kinds" ("track","album","artist","album_artist") to a(pylast_method, arg_extractor)tuple.fetch_*methods with a singlefetch(kind, obj)that dispatches via this registry._tags_forwrapper — its logic is inlined into the now-publicfetch_genres.pylast.Album.get_top_tags()inconsistency fixed in 2014.__init__.py:client.fetch(kind, obj)— the client now owns field extraction (e.g.obj.artist,obj.album), removing that concern from the plugin layer.test_lastgenre.py:monkeypatchonLastFmClient.fetchreplaces three separate method patches.Impact