Skip to content

lastgenre: Refactor _get_genre - #6474

Open
JOJ0 wants to merge 8 commits into
masterfrom
lastgenre_refactor_get_genre
Open

lastgenre: Refactor _get_genre#6474
JOJ0 wants to merge 8 commits into
masterfrom
lastgenre_refactor_get_genre

Conversation

@JOJ0

@JOJ0 JOJ0 commented Mar 30, 2026

Copy link
Copy Markdown
Member

Description

The monolithic _get_genre method was broken down into several private instance methods and refactored for readability. The contract is kept and is already well tested (test_get_genre)

  • Core Helpers - were moved from within _get_genre to reusable instance methods:

    • _try_resolve_stage: Handles the canonicalization and logging of genres for a specific stage.
    • _configured_fallback: Provides the configured fallback genre.
  • Lookup Stages - some were complex enough to deserve their own instance method for readability, some stay inline in _get_genre:

    • _try_resolve_existing_genres: Manages the initial check for pre-existing genres and the cleanup_existing logic.
    • track stage: stays inline
    • album stage: indentical to track stage, but not worth moving / deduplication doesn't buy much (see subsequent PR though)
    • _fetch_artist_stage: Fetches and resolves artist-level genres, including multi-valued album artists and "Various Artists" logic.
    • _fetch_va_genres: specifically handles the plurality logic for "Various Artists" albums.
  • Fallbacks:

    • _try_resolve_original_fallback: Handles the "keep_existing" logic that attempts to use/canonicalize originally present genres if no new ones are found.

Make sure to also look at subsequent PR's:

To Do

  • Documentation
  • Changelog
  • Tests (_get_genre was already well covered and the signature of the method was kept)

@JOJ0
JOJ0 requested a review from a team as a code owner March 30, 2026 17:17
@github-actions

Copy link
Copy Markdown

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.

@JOJ0
JOJ0 changed the base branch from master to lastgenre_aliases March 30, 2026 17:20
@codecov

codecov Bot commented Mar 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.84416% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.61%. Comparing base (e2889d1) to head (b4a7caf).
⚠️ Report is 38 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/__init__.py 55.84% 25 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6474      +/-   ##
==========================================
- Coverage   75.62%   75.61%   -0.01%     
==========================================
  Files         163      163              
  Lines       21318    21324       +6     
  Branches     3361     3362       +1     
==========================================
+ Hits        16122    16125       +3     
- Misses       4405     4409       +4     
+ Partials      791      790       -1     
Files with missing lines Coverage Δ
beetsplug/lastgenre/__init__.py 81.25% <55.84%> (-1.38%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JOJ0
JOJ0 marked this pull request as draft March 30, 2026 20:05
@JOJ0 JOJ0 mentioned this pull request Apr 3, 2026
3 tasks
@JOJ0 JOJ0 added the plugin Pull requests that are plugins related label Apr 4, 2026
@snejus snejus added lastgenre lastgenre plugin and removed plugin Pull requests that are plugins related labels Apr 4, 2026
Base automatically changed from lastgenre_aliases to master July 15, 2026 14:09
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch 3 times, most recently from 806bc74 to ba7b59a Compare July 28, 2026 13:48
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch 2 times, most recently from dfef785 to af3f67f Compare July 30, 2026 04:15
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from af3f67f to c54f8bb Compare July 30, 2026 04:17
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from c54f8bb to 9e3e0e2 Compare July 30, 2026 04:51
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from 9e3e0e2 to b4a7caf Compare July 30, 2026 05:47
@JOJ0
JOJ0 marked this pull request as ready for review July 30, 2026 05:53
Copilot AI review requested due to automatic review settings July 30, 2026 05:53
@github-actions

Copy link
Copy Markdown

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

grug see PR break big _get_genre into smaller helper methods, so code easier read and reason about, but keep same external behavior for lastgenre plugin.

Changes:

  • move fallback + per-stage “resolve + log” logic into private instance helpers
  • pull out “existing genres / cleanup_existing” handling and “original fallback” handling into dedicated helpers
  • pull out artist-stage fetching (incl. VA plurality) into helper, so _get_genre main flow more straight

Comment thread beetsplug/lastgenre/__init__.py
Comment thread beetsplug/lastgenre/__init__.py
Comment thread beetsplug/lastgenre/__init__.py
@JOJ0
JOJ0 marked this pull request as draft July 30, 2026 06:13
@JOJ0
JOJ0 marked this pull request as ready for review July 30, 2026 08:52
@github-actions

Copy link
Copy Markdown

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.

@JOJ0 JOJ0 added the refactor label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lastgenre lastgenre plugin refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants