Skip to content

Commit ccda740

Browse files
committed
Utilize new way of declaring a NamedTuple
1 parent 38a26af commit ccda740

File tree

7 files changed

+768
-703
lines changed

7 files changed

+768
-703
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,6 @@ ENV/
9191
/.pydevproject
9292
/.settings
9393
.vscode
94+
95+
# pyright
96+
pyrightconfig.json

beets/autotag/hooks.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import annotations
1818

1919
import re
20-
from collections import namedtuple
2120
from functools import total_ordering
2221
from typing import (
2322
Any,
@@ -26,6 +25,7 @@
2625
Iterable,
2726
Iterator,
2827
List,
28+
NamedTuple,
2929
Optional,
3030
Tuple,
3131
TypeVar,
@@ -589,11 +589,18 @@ def add_string(self, key: str, str1: Optional[str], str2: Optional[str]):
589589

590590
# Structures that compose all the information for a candidate match.
591591

592-
AlbumMatch = namedtuple(
593-
"AlbumMatch", ["distance", "info", "mapping", "extra_items", "extra_tracks"]
594-
)
595592

596-
TrackMatch = namedtuple("TrackMatch", ["distance", "info"])
593+
class AlbumMatch(NamedTuple):
594+
distance: Distance
595+
info: AlbumInfo
596+
mapping: Dict[Item, TrackInfo]
597+
extra_items: List[Item]
598+
extra_tracks: List[TrackInfo]
599+
600+
601+
class TrackMatch(NamedTuple):
602+
distance: Distance
603+
info: TrackInfo
597604

598605

599606
# Aggregation of sources.

beets/autotag/match.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import datetime
2121
import re
22-
from collections import namedtuple
2322
from typing import (
2423
Any,
2524
Dict,
2625
Iterable,
2726
List,
27+
NamedTuple,
2828
Optional,
2929
Sequence,
3030
Tuple,
@@ -76,7 +76,10 @@ class Recommendation(OrderedEnum):
7676
# consists of a list of possible candidates (i.e., AlbumInfo or TrackInfo
7777
# objects) and a recommendation value.
7878

79-
Proposal = namedtuple("Proposal", ("candidates", "recommendation"))
79+
80+
class Proposal(NamedTuple):
81+
candidates: List[Any]
82+
recommendation: Recommendation
8083

8184

8285
# Primary matching functionality.

beets/ui/commands.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import os
2121
import re
22-
from collections import Counter, namedtuple
22+
from collections import Counter
2323
from itertools import chain
2424
from platform import python_version
25-
from typing import Sequence
25+
from typing import Any, NamedTuple, Sequence
2626

2727
import beets
2828
from beets import autotag, config, importer, library, logging, plugins, ui, util
@@ -47,7 +47,6 @@
4747
from . import _store_dict
4848

4949
VARIOUS_ARTISTS = "Various Artists"
50-
PromptChoice = namedtuple("PromptChoice", ["short", "long", "callback"])
5150

5251
# Global logger.
5352
log = logging.getLogger("beets")
@@ -665,7 +664,7 @@ def show_match_tracks(self):
665664
"""
666665
# Tracks.
667666
# match is an AlbumMatch named tuple, mapping is a dict
668-
# Sort the pairs by the track_info index (at index 1 of the namedtuple)
667+
# Sort the pairs by the track_info index (at index 1 of the NamedTuple)
669668
pairs = list(self.match.mapping.items())
670669
pairs.sort(key=lambda item_and_track_info: item_and_track_info[1].index)
671670
# Build up LHS and RHS for track difference display. The `lines` list
@@ -840,6 +839,12 @@ def _summary_judgment(rec):
840839
return action
841840

842841

842+
class PromptChoice(NamedTuple):
843+
short: str
844+
long: str
845+
callback: Any
846+
847+
843848
def choose_candidate(
844849
candidates,
845850
singleton,

beets/util/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import sys
2727
import tempfile
2828
import traceback
29-
from collections import Counter, namedtuple
29+
from collections import Counter
3030
from contextlib import suppress
3131
from enum import Enum
3232
from logging import Logger
@@ -40,6 +40,7 @@
4040
Iterable,
4141
List,
4242
MutableSequence,
43+
NamedTuple,
4344
Optional,
4445
Pattern,
4546
Sequence,
@@ -847,7 +848,9 @@ def convert(arg) -> str:
847848

848849

849850
# stdout and stderr as bytes
850-
CommandOutput = namedtuple("CommandOutput", ("stdout", "stderr"))
851+
class CommandOutput(NamedTuple):
852+
stdout: bytes
853+
stderr: bytes
851854

852855

853856
def command_output(

0 commit comments

Comments
 (0)