-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Create common info class #5963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create common info class #5963
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a generic Info
base class that centralizes shared attributes and initialization logic between AlbumInfo
and TrackInfo
. The refactoring aims to reduce code duplication and improve maintainability.
- Extracts common functionality into a new
Info
base class extendingAttrDict
- Consolidates shared attributes and implements a unified
copy()
method usingcopy.deepcopy
- Alphabetizes constructor parameters and makes them explicit with keyword-only arguments
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5963 +/- ##
==========================================
- Coverage 66.49% 66.47% -0.03%
==========================================
Files 117 117
Lines 18122 18105 -17
Branches 3071 3071
==========================================
- Hits 12051 12036 -15
+ Misses 5415 5414 -1
+ Partials 656 655 -1
🚀 New features to boost your workflow:
|
As a short note, we already do this in |
I see. I looked into making them dataclasses, however we're limited due to backwards compatibility and need to keep dict-like item access in place :/ |
@sourcery-ai review |
Reviewer's GuideThis PR introduces a new Info base class in place of duplicated initialisation logic in AlbumInfo and TrackInfo, reorganising constructors, centralising copy functionality using deepcopy, cleaning up logging, and enhancing type annotations and documentation. Class diagram for new Info base class and its usage in AlbumInfo and TrackInfoclassDiagram
class AttrDict {
+copy() Self
+__getattr__(attr: str) V
+__setattr__(key: str, value: V)
+__hash__() int
}
class Info {
+album: str | None
+artist_credit: str | None
+artist_id: str | None
+artist: str | None
+artists_credit: list[str] | None
+artists_ids: list[str] | None
+artists: list[str] | None
+artist_sort: str | None
+artists_sort: list[str] | None
+data_source: str | None
+data_url: str | None
+genre: str | None
+media: str | None
+__init__(...)
}
class AlbumInfo {
+tracks: list[TrackInfo]
+album_id: str | None
+albumdisambig: str | None
+albumstatus: str | None
+albumtype: str | None
+albumtypes: list[str] | None
+asin: str | None
+barcode: str | None
+catalognum: str | None
+country: str | None
+day: int | None
+discogs_albumid: str | None
+discogs_artistid: str | None
+discogs_labelid: str | None
+label: str | None
+language: str | None
+mediums: int | None
+month: int | None
+original_day: int | None
+original_month: int | None
+original_year: int | None
+release_group_title: str | None
+releasegroup_id: str | None
+releasegroupdisambig: str | None
+script: str | None
+style: str | None
+va: bool
+year: int | None
+__init__(...)
}
class TrackInfo {
+arranger: str | None
+bpm: str | None
+composer: str | None
+composer_sort: str | None
+disctitle: str | None
+index: int | None
+initial_key: str | None
+length: float | None
+lyricist: str | None
+mb_workid: str | None
+medium: int | None
+medium_index: int | None
+medium_total: int | None
+release_track_id: str | None
+title: str | None
+track_alt: str | None
+track_id: str | None
+work: str | None
+work_disambig: str | None
+__init__(...)
}
AttrDict <|-- Info
Info <|-- AlbumInfo
Info <|-- TrackInfo
AlbumInfo "1" o-- "*" TrackInfo
Class diagram for updated copy() method centralisationclassDiagram
class AttrDict {
+copy() Self
}
class Info {
+copy() Self
}
class AlbumInfo {
+copy() Self
}
class TrackInfo {
+copy() Self
}
AttrDict <|-- Info
Info <|-- AlbumInfo
Info <|-- TrackInfo
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `beets/autotag/hooks.py:54` </location>
<code_context>
-class AlbumInfo(AttrDict[Any]):
- """Describes a canonical release that may be used to match a release
- in the library. Consists of these data members:
+class Info(AttrDict[Any]):
+ """Container for metadata about a musical entity."""
+
+ def __init__(
+ self,
+ album: str | None = None,
</code_context>
<issue_to_address>
Info class constructor sets many attributes directly before calling update.
If kwargs contain keys matching the directly set attributes, their values may be overwritten. Please confirm this behavior is intended.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
4e442c9
to
19c43c9
Compare
Context
See #5916 where we've come across a need to define common logic between
TrackInfo
andAlbumInfo
.Changes
Info
base (extendsAttrDict
) used byAlbumInfo
/TrackInfo
to centralize shared attributes and initialisation logic.copy()
method usingcopy.deepcopy
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:
Enhancements:
Chores: