Skip to content

Conversation

mikeroll
Copy link

@mikeroll mikeroll commented Aug 6, 2025

Description

Fixes #5010. Fixes #5633.

I've started with the most naive solution - this is essentially the same piece of logic in five places - as I'm not yet feeling comfortable to mess with AlbumInfo/TrackInfo, nor have I found an optimal place to do so. Some pointers on centralizing this (if it makes sense?) are welcome!

I would proceed adding the tests after the initial feedback. Thanks!

To Do

  • Documentation
  • Changelog
  • Tests

Copy link

github-actions bot commented Aug 6, 2025

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.

Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.72%. Comparing base (e3574a7) to head (0d2ef50).
⚠️ Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
beets/autotag/distance.py 50.00% 2 Missing and 2 partials ⚠️
beets/ui/commands.py 42.85% 2 Missing and 2 partials ⚠️
beets/autotag/match.py 33.33% 1 Missing and 1 partial ⚠️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@snejus
Copy link
Member

snejus commented Aug 25, 2025

@mikeroll that is indeed a lot of duplication. I think a better approach would be to define an attribute on TrackInfo / AlbumInfo:

    @property
    def artist(self) -> str | None:
        artist_credit = (
            self["artist_credit"] if beets.config["artist_credit"] else None
        )

        return artist_credit or self["artist"]

    @artist.setter
    def artist(self, value: str) -> None:
        self["artist"] = value

Let me first refactor these two classes to isolate common functionality into a common Info class where you will be able to define this attribute! I'd already done this in my fork a while ago so I just need to find the relevant commit and open a PR with it.

@snejus snejus mentioned this pull request Aug 26, 2025
snejus added a commit that referenced this pull request Sep 8, 2025
### Context
See #5916 where we've come across a
need to define common logic between `TrackInfo` and `AlbumInfo`.

### Changes
- Introduce generic `Info` base (extends `AttrDict`) used by `AlbumInfo`
/ `TrackInfo` to centralize shared attributes and initialisation logic.
- Sort keyword parameters in each constructor alphabetically and make
them explicit.
- Deduplicate and simplify shared `copy()` method using `copy.deepcopy`
- Improve type hints and documentation.
- Drop unused logging artifacts.

## Summary by Sourcery

Refactor metadata-handling classes by extracting common functionality
into a new Info base, updating AlbumInfo and TrackInfo to extend it with
explicit sorted parameters, unify their copy logic, improve type
annotations and docs, and drop obsolete logging code

New Features:
- Introduce a generic Info base class to centralize shared logic for
AlbumInfo and TrackInfo

Enhancements:
- Alphabetically sort and explicitly declare constructor keyword
parameters for consistency
- Unify and simplify the copy() implementation in AttrDict using
deepcopy
- Enhance type hints and documentation for metadata classes

Chores:
- Remove unused logging imports and artifacts
@snejus
Copy link
Member

snejus commented Sep 27, 2025

@mikeroll forgot to mention that my PR has already been merged. Try to rebase on master try my suggestion above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants