Utilize new way of declaring a NamedTuple

This commit is contained in:
Konstantin 2024-08-25 16:26:19 +02:00
parent 38a26af149
commit ccda7405b9
7 changed files with 767 additions and 702 deletions

3
.gitignore vendored
View file

@ -91,3 +91,6 @@ ENV/
/.pydevproject
/.settings
.vscode
# pyright
pyrightconfig.json

View file

@ -17,7 +17,6 @@
from __future__ import annotations
import re
from collections import namedtuple
from functools import total_ordering
from typing import (
Any,
@ -26,6 +25,7 @@ from typing import (
Iterable,
Iterator,
List,
NamedTuple,
Optional,
Tuple,
TypeVar,
@ -589,11 +589,18 @@ class Distance:
# 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.

View file

@ -19,12 +19,12 @@ releases and tracks.
import datetime
import re
from collections import namedtuple
from typing import (
Any,
Dict,
Iterable,
List,
NamedTuple,
Optional,
Sequence,
Tuple,
@ -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.

View file

@ -19,10 +19,10 @@ interface.
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
@ -47,7 +47,6 @@ from beets.util import (
from . import _store_dict
VARIOUS_ARTISTS = "Various Artists"
PromptChoice = namedtuple("PromptChoice", ["short", "long", "callback"])
# Global logger.
log = logging.getLogger("beets")
@ -665,7 +664,7 @@ class AlbumChange(ChangeRepresentation):
"""
# 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
@ -840,6 +839,12 @@ def _summary_judgment(rec):
return action
class PromptChoice(NamedTuple):
short: str
long: str
callback: Any
def choose_candidate(
candidates,
singleton,

View file

@ -26,7 +26,7 @@ import subprocess
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
@ -40,6 +40,7 @@ from typing import (
Iterable,
List,
MutableSequence,
NamedTuple,
Optional,
Pattern,
Sequence,
@ -847,7 +848,9 @@ def convert_command_args(args: List[bytes]) -> List[str]:
# stdout and stderr as bytes
CommandOutput = namedtuple("CommandOutput", ("stdout", "stderr"))
class CommandOutput(NamedTuple):
stdout: bytes
stderr: bytes
def command_output(

1407
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -22,10 +22,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
]
packages = [
{ include = "beets" },
{ include = "beetsplug" },
]
packages = [{ include = "beets" }, { include = "beetsplug" }]
[tool.poetry.urls]
Changelog = "https://github.com/beetbox/beets/blob/master/docs/changelog.rst"
@ -109,7 +106,9 @@ tomli = ">=2.0.1"
[tool.poetry.extras]
# inline comments note required external / non-python dependencies
absubmit = ["requests"] # extractor binary from https://acousticbrainz.org/download
absubmit = [
"requests",
] # extractor binary from https://acousticbrainz.org/download
aura = ["flask", "flask-cors", "Pillow"]
# badfiles # mp3val and flac
beatport = ["requests-oauthlib"]