Skip to content

Commit

Permalink
Utilize new way of declaring a NamedTuple
Browse files Browse the repository at this point in the history
  • Loading branch information
amogus07 committed Aug 25, 2024
1 parent 38a26af commit ccda740
Show file tree
Hide file tree
Showing 7 changed files with 768 additions and 703 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ ENV/
/.pydevproject
/.settings
.vscode

# pyright
pyrightconfig.json
17 changes: 12 additions & 5 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import re
from collections import namedtuple
from functools import total_ordering
from typing import (
Any,
Expand All @@ -26,6 +25,7 @@
Iterable,
Iterator,
List,
NamedTuple,
Optional,
Tuple,
TypeVar,
Expand Down Expand Up @@ -589,11 +589,18 @@ def add_string(self, key: str, str1: Optional[str], str2: Optional[str]):

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

AlbumMatch = namedtuple(
"AlbumMatch", ["distance", "info", "mapping", "extra_items", "extra_tracks"]
)

TrackMatch = namedtuple("TrackMatch", ["distance", "info"])
class AlbumMatch(NamedTuple):
distance: Distance
info: AlbumInfo
mapping: Dict[Item, TrackInfo]
extra_items: List[Item]
extra_tracks: List[TrackInfo]


class TrackMatch(NamedTuple):
distance: Distance
info: TrackInfo


# Aggregation of sources.
Expand Down
7 changes: 5 additions & 2 deletions beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

import datetime
import re
from collections import namedtuple
from typing import (
Any,
Dict,
Iterable,
List,
NamedTuple,
Optional,
Sequence,
Tuple,
Expand Down Expand Up @@ -76,7 +76,10 @@ class Recommendation(OrderedEnum):
# consists of a list of possible candidates (i.e., AlbumInfo or TrackInfo
# objects) and a recommendation value.

Proposal = namedtuple("Proposal", ("candidates", "recommendation"))

class Proposal(NamedTuple):
candidates: List[Any]
recommendation: Recommendation


# Primary matching functionality.
Expand Down
13 changes: 9 additions & 4 deletions beets/ui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import os
import re
from collections import Counter, namedtuple
from collections import Counter
from itertools import chain
from platform import python_version
from typing import Sequence
from typing import Any, NamedTuple, Sequence

import beets
from beets import autotag, config, importer, library, logging, plugins, ui, util
Expand All @@ -47,7 +47,6 @@
from . import _store_dict

VARIOUS_ARTISTS = "Various Artists"
PromptChoice = namedtuple("PromptChoice", ["short", "long", "callback"])

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


class PromptChoice(NamedTuple):
short: str
long: str
callback: Any


def choose_candidate(
candidates,
singleton,
Expand Down
7 changes: 5 additions & 2 deletions beets/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import sys
import tempfile
import traceback
from collections import Counter, namedtuple
from collections import Counter
from contextlib import suppress
from enum import Enum
from logging import Logger
Expand All @@ -40,6 +40,7 @@
Iterable,
List,
MutableSequence,
NamedTuple,
Optional,
Pattern,
Sequence,
Expand Down Expand Up @@ -847,7 +848,9 @@ def convert(arg) -> str:


# stdout and stderr as bytes
CommandOutput = namedtuple("CommandOutput", ("stdout", "stderr"))
class CommandOutput(NamedTuple):
stdout: bytes
stderr: bytes


def command_output(
Expand Down
Loading

0 comments on commit ccda740

Please sign in to comment.