Skip to content

Commit ec60ec6

Browse files
committed
hooks: Generalise AlbumMatch and TrackMatch into Match
1 parent 8636f7e commit ec60ec6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

beets/autotag/hooks.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from __future__ import annotations
1818

1919
from copy import deepcopy
20-
from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar
20+
from dataclasses import dataclass
21+
from functools import cached_property
22+
from typing import TYPE_CHECKING, Any, TypeVar
2123

2224
from typing_extensions import Self
2325

@@ -214,20 +216,24 @@ def __init__(
214216

215217

216218
# Structures that compose all the information for a candidate match.
219+
@dataclass
220+
class Match:
221+
distance: Distance
222+
info: Info
217223

218224

219-
class AlbumMatch(NamedTuple):
220-
distance: Distance
225+
@dataclass
226+
class AlbumMatch(Match):
221227
info: AlbumInfo
222228
mapping: list[tuple[Item, TrackInfo]]
223229
extra_items: list[Item]
224230
extra_tracks: list[TrackInfo]
225231

226-
@property
232+
@cached_property
227233
def items(self) -> list[Item]:
228234
return [i for i, _ in self.mapping]
229235

230236

231-
class TrackMatch(NamedTuple):
232-
distance: Distance
237+
@dataclass
238+
class TrackMatch(Match):
233239
info: TrackInfo

0 commit comments

Comments
 (0)