-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introduce Info.name property and add types to match details functions #6142
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
base: master
Are you sure you want to change the base?
Changes from all commits
3bd3200
8636f7e
ec60ec6
95df036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,7 +422,7 @@ def track_distance( | |
| def distance( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Low code quality found in distance - 16% ( ExplanationThe quality score for this function is below the quality threshold of 25%.This score is a combination of the method length, cognitive complexity and working memory. How can you solve this? It might be worth refactoring this function to make it shorter and more readable.
|
||
| items: Sequence[Item], | ||
| album_info: AlbumInfo, | ||
| mapping: dict[Item, TrackInfo], | ||
| mapping: list[tuple[Item, TrackInfo]], | ||
| ) -> Distance: | ||
| """Determines how "significant" an album metadata change would be. | ||
| Returns a Distance object. `album_info` is an AlbumInfo object | ||
|
|
@@ -518,7 +518,7 @@ def distance( | |
|
|
||
| # Tracks. | ||
| dist.tracks = {} | ||
| for item, track in mapping.items(): | ||
| for item, track in mapping: | ||
| dist.tracks[track] = track_distance(item, track, album_info.va) | ||
| dist.add("tracks", dist.tracks[track].distance) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,14 @@ | |
| from __future__ import annotations | ||
|
|
||
| from copy import deepcopy | ||
| from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar | ||
| from dataclasses import dataclass | ||
| from functools import cached_property | ||
| from typing import TYPE_CHECKING, Any, TypeVar | ||
|
|
||
| from typing_extensions import Self | ||
|
|
||
| from beets.util import cached_classproperty | ||
|
|
||
| if TYPE_CHECKING: | ||
| from beets.library import Item | ||
|
|
||
|
|
@@ -54,6 +58,10 @@ def __hash__(self) -> int: # type: ignore[override] | |
| class Info(AttrDict[Any]): | ||
| """Container for metadata about a musical entity.""" | ||
|
|
||
| @cached_property | ||
| def name(self) -> str: | ||
| raise NotImplementedError | ||
|
|
||
| def __init__( | ||
| self, | ||
| album: str | None = None, | ||
|
|
@@ -95,6 +103,10 @@ class AlbumInfo(Info): | |
| user items, and later to drive tagging decisions once selected. | ||
| """ | ||
|
|
||
| @cached_property | ||
| def name(self) -> str: | ||
| return self.album or "" | ||
|
|
||
| def __init__( | ||
| self, | ||
| tracks: list[TrackInfo], | ||
|
|
@@ -167,6 +179,10 @@ class TrackInfo(Info): | |
| stand alone for singleton matching. | ||
| """ | ||
|
|
||
| @cached_property | ||
| def name(self) -> str: | ||
| return self.title or "" | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
|
|
@@ -214,16 +230,28 @@ def __init__( | |
|
|
||
|
|
||
| # Structures that compose all the information for a candidate match. | ||
| @dataclass | ||
| class Match: | ||
| distance: Distance | ||
| info: Info | ||
|
|
||
| @cached_classproperty | ||
| def type(cls) -> str: | ||
|
||
| return cls.__name__.removesuffix("Match") # type: ignore[attr-defined] | ||
|
|
||
| class AlbumMatch(NamedTuple): | ||
| distance: Distance | ||
|
|
||
| @dataclass | ||
| class AlbumMatch(Match): | ||
| info: AlbumInfo | ||
| mapping: dict[Item, TrackInfo] | ||
| mapping: list[tuple[Item, TrackInfo]] | ||
| extra_items: list[Item] | ||
| extra_tracks: list[TrackInfo] | ||
|
|
||
| @cached_property | ||
| def items(self) -> list[Item]: | ||
| return [i for i, _ in self.mapping] | ||
|
|
||
| class TrackMatch(NamedTuple): | ||
| distance: Distance | ||
|
|
||
| @dataclass | ||
| class TrackMatch(Match): | ||
| info: TrackInfo | ||
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.
issue (code-quality): Low code quality found in apply_metadata - 19% (
low-code-quality)Explanation
The quality score for this function is below the quality threshold of 25%.This score is a combination of the method length, cognitive complexity and working memory.
How can you solve this?
It might be worth refactoring this function to make it shorter and more readable.
their own functions. This is the most important thing you can do - ideally a
function should be less than 10 lines.
sits together within the function rather than being scattered.