Skip to content

typing: type and refactor duplicates plugin - #6947

Open
snejus wants to merge 2 commits into
type-mpdstats-thumbnails-pluginsfrom
type-duplicates-plugin
Open

typing: type and refactor duplicates plugin#6947
snejus wants to merge 2 commits into
type-mpdstats-thumbnails-pluginsfrom
type-duplicates-plugin

Conversation

@snejus

@snejus snejus commented Aug 22, 2026

Copy link
Copy Markdown
Member

Part of #6924.

What changed

  • Types added to beetsplug/duplicates.py.
  • Refactors beetsplug/duplicates.py so album and item commands now share one execution path through _run_command().
  • Replaces the old generic _merge() dispatch with an explicit merge_func passed into _duplicates(), so album and item merge behavior stays separate but simpler.
  • Tightens typing across the plugin by using clearer Album, Item, AlbumOrItem, and LibModel annotations in the main helper methods.

Why it matters

  • The plugin's architecture is now more direct: command setup decides 'albums' vs 'items', and the shared duplicate-processing flow handles the rest.
  • This removes branching and type ambiguity from the core duplicate logic, which makes the code easier to follow and safer to change.
  • Functional behavior stays the same at a high level, but the plugin is now easier to maintain, reason about, and extend.

Copilot AI lite review requested due to automatic review settings August 22, 2026 08:57
@snejus
snejus requested a review from a team as a code owner August 22, 2026 08:57
@github-actions github-actions Bot added the duplicates duplicates plugin label Aug 22, 2026
@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 make beetsplug/duplicates.py more typed, and refactor so album + item modes share one main flow. goal look like: fewer branches, clearer types, still same user behavior.

Changes:

  • add typing across duplicates plugin, incl. AlbumOrItem + clearer helper signatures
  • refactor command path so both album + item go through new _run_command()
  • replace old generic merge dispatch with explicit merge_func passed into _duplicates()
Suppressed comments (1)

beetsplug/duplicates.py:287

  • grug see log line still say "on item" but var now model (and can be album). log text should say "model" so debug not lie.
            self._log.debug(
                "key {} on item {.filepath} cached:not computing checksum",
                key,
                model,
            )

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread beetsplug/duplicates.py
Comment on lines +197 to +200
if checksum:
for i in items:
k, _ = self._checksum(i, checksum)
keys = [k]
Comment thread beetsplug/duplicates.py
fmt: str,
remove: bool,
) -> None:
"""Process Item `item`."""
Comment thread beetsplug/duplicates.py
Comment on lines 258 to 261
"""Run external `prog` on file path associated with `item`, cache
output as flexattr on a key that is the name of the program, and
return the key, checksum tuple.
"""
Comment thread beetsplug/duplicates.py
Comment on lines 268 to 272
self._log.debug(
"key {} on item {.filepath} not cached:computing checksum",
key,
item,
model,
)
Comment thread beetsplug/duplicates.py
Comment on lines +146 to +150
if self.config["album"].get(bool):
self._run_command(
lib.albums(args),
keys or ["mb_albumid"],
"$albumartist - $album",
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.81250% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.07%. Comparing base (aa2190d) to head (1b58420).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/duplicates.py 57.81% 20 Missing and 7 partials ⚠️
Additional details and impacted files
@@                         Coverage Diff                          @@
##           type-mpdstats-thumbnails-plugins    #6947      +/-   ##
====================================================================
+ Coverage                             76.02%   76.07%   +0.04%     
====================================================================
  Files                                   164      164              
  Lines                                 21615    21599      -16     
  Branches                               3342     3338       -4     
====================================================================
- Hits                                  16433    16431       -2     
+ Misses                                 4386     4374      -12     
+ Partials                                796      794       -2     
Files with missing lines Coverage Δ
beetsplug/duplicates.py 52.28% <57.81%> (+3.18%) ⬆️

... 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.

@snejus
snejus force-pushed the type-mpdstats-thumbnails-plugins branch from aa2190d to 3741bd1 Compare August 23, 2026 17:03
@snejus
snejus requested a review from semohr as a code owner August 23, 2026 17:03
@snejus
snejus force-pushed the type-duplicates-plugin branch from 1b58420 to a8d11d5 Compare August 24, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicates duplicates plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants