Skip to content

lastgenre: Refactor _get_genre - #6474

Merged
JOJ0 merged 11 commits into
masterfrom
lastgenre_refactor_get_genre
Aug 18, 2026
Merged

lastgenre: Refactor _get_genre#6474
JOJ0 merged 11 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 a reusable instance method and a cached_property:

    • _try_resolve_stage: Handles the canonicalization and logging of genres for a specific stage.
    • fallback: Provides the configured fallback genre. Is used as a last resort in _try_resolve_existing_genres and when _get_genre couldn't find any genre in any stage at all.
  • 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 when force is disabled.
    • 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. (Not required, refactor only)
  • 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 74.35897% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.11%. Comparing base (5406ed7) to head (87633a8).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/lastgenre/__init__.py 74.35% 11 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6474      +/-   ##
==========================================
+ Coverage   76.06%   76.11%   +0.04%     
==========================================
  Files         163      163              
  Lines       21146    21151       +5     
  Branches     3334     3334              
==========================================
+ Hits        16085    16099      +14     
+ Misses       4273     4264       -9     
  Partials      788      788              
Files with missing lines Coverage Δ
beetsplug/lastgenre/__init__.py 86.06% <74.35%> (+3.43%) ⬆️
🚀 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

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from e2f60a5 to 47ae4ab Compare August 12, 2026 04:18
@JOJ0

JOJ0 commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@semohr @snejus @henry-oberholtzer @Serene-Arc anyone care to review a no-op refactor-only PR? :-) Thanks :-)

Comment thread beetsplug/lastgenre/__init__.py Outdated
Comment thread beetsplug/lastgenre/__init__.py Outdated
Comment thread beetsplug/lastgenre/__init__.py Outdated
Comment thread beetsplug/lastgenre/__init__.py Outdated
Comment thread beetsplug/lastgenre/__init__.py
Comment thread beetsplug/lastgenre/__init__.py Outdated
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch 2 times, most recently from 929b3ea to 47f6c96 Compare August 16, 2026 14:55
@JOJ0
JOJ0 requested a review from snejus August 16, 2026 15:49
@JOJ0

JOJ0 commented Aug 16, 2026

Copy link
Copy Markdown
Member Author

Thanks @snejus that was great feedback! 👍 I think I addressed all of it.

@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from ae56202 to ceb2d5c Compare August 17, 2026 06:00
Comment thread beetsplug/lastgenre/__init__.py
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from cf8cb27 to c48c2e7 Compare August 17, 2026 06:51
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from c48c2e7 to dae33c0 Compare August 18, 2026 04:44
@JOJ0
JOJ0 force-pushed the lastgenre_refactor_get_genre branch from dae33c0 to 87633a8 Compare August 18, 2026 05:01
@JOJ0

JOJ0 commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Hi @snejus, thanks for the approval. Did two more tiny things: Fixed mypy errors, accidentally applied GenresWithLable alias to _fetch_artist_stage which is slightly different. Fixed another 2-line docstring/comment (below type alias CanonTree).

@JOJ0
JOJ0 merged commit e1ffd17 into master Aug 18, 2026
25 checks passed
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