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 /.pydevproject
/.settings /.settings
.vscode .vscode
# pyright
pyrightconfig.json

View file

@ -17,7 +17,6 @@
from __future__ import annotations from __future__ import annotations
import re import re
from collections import namedtuple
from functools import total_ordering from functools import total_ordering
from typing import ( from typing import (
Any, Any,
@ -26,6 +25,7 @@ from typing import (
Iterable, Iterable,
Iterator, Iterator,
List, List,
NamedTuple,
Optional, Optional,
Tuple, Tuple,
TypeVar, TypeVar,
@ -589,11 +589,18 @@ class Distance:
# Structures that compose all the information for a candidate match. # 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. # Aggregation of sources.

View file

@ -19,12 +19,12 @@ releases and tracks.
import datetime import datetime
import re import re
from collections import namedtuple
from typing import ( from typing import (
Any, Any,
Dict, Dict,
Iterable, Iterable,
List, List,
NamedTuple,
Optional, Optional,
Sequence, Sequence,
Tuple, Tuple,
@ -76,7 +76,10 @@ class Recommendation(OrderedEnum):
# consists of a list of possible candidates (i.e., AlbumInfo or TrackInfo # consists of a list of possible candidates (i.e., AlbumInfo or TrackInfo
# objects) and a recommendation value. # objects) and a recommendation value.
Proposal = namedtuple("Proposal", ("candidates", "recommendation"))
class Proposal(NamedTuple):
candidates: List[Any]
recommendation: Recommendation
# Primary matching functionality. # Primary matching functionality.

View file

@ -19,10 +19,10 @@ interface.
import os import os
import re import re
from collections import Counter, namedtuple from collections import Counter
from itertools import chain from itertools import chain
from platform import python_version from platform import python_version
from typing import Sequence from typing import Any, NamedTuple, Sequence
import beets import beets
from beets import autotag, config, importer, library, logging, plugins, ui, util from beets import autotag, config, importer, library, logging, plugins, ui, util
@ -47,7 +47,6 @@ from beets.util import (
from . import _store_dict from . import _store_dict
VARIOUS_ARTISTS = "Various Artists" VARIOUS_ARTISTS = "Various Artists"
PromptChoice = namedtuple("PromptChoice", ["short", "long", "callback"])
# Global logger. # Global logger.
log = logging.getLogger("beets") log = logging.getLogger("beets")
@ -665,7 +664,7 @@ class AlbumChange(ChangeRepresentation):
""" """
# Tracks. # Tracks.
# match is an AlbumMatch named tuple, mapping is a dict # 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 = list(self.match.mapping.items())
pairs.sort(key=lambda item_and_track_info: item_and_track_info[1].index) 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 # Build up LHS and RHS for track difference display. The `lines` list
@ -840,6 +839,12 @@ def _summary_judgment(rec):
return action return action
class PromptChoice(NamedTuple):
short: str
long: str
callback: Any
def choose_candidate( def choose_candidate(
candidates, candidates,
singleton, singleton,

View file

@ -26,7 +26,7 @@ import subprocess
import sys import sys
import tempfile import tempfile
import traceback import traceback
from collections import Counter, namedtuple from collections import Counter
from contextlib import suppress from contextlib import suppress
from enum import Enum from enum import Enum
from logging import Logger from logging import Logger
@ -40,6 +40,7 @@ from typing import (
Iterable, Iterable,
List, List,
MutableSequence, MutableSequence,
NamedTuple,
Optional, Optional,
Pattern, Pattern,
Sequence, Sequence,
@ -847,7 +848,9 @@ def convert_command_args(args: List[bytes]) -> List[str]:
# stdout and stderr as bytes # stdout and stderr as bytes
CommandOutput = namedtuple("CommandOutput", ("stdout", "stderr")) class CommandOutput(NamedTuple):
stdout: bytes
stderr: bytes
def command_output( 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 :: 3.10",
"Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: CPython",
] ]
packages = [ packages = [{ include = "beets" }, { include = "beetsplug" }]
{ include = "beets" },
{ include = "beetsplug" },
]
[tool.poetry.urls] [tool.poetry.urls]
Changelog = "https://github.com/beetbox/beets/blob/master/docs/changelog.rst" Changelog = "https://github.com/beetbox/beets/blob/master/docs/changelog.rst"
@ -109,7 +106,9 @@ tomli = ">=2.0.1"
[tool.poetry.extras] [tool.poetry.extras]
# inline comments note required external / non-python dependencies # 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"] aura = ["flask", "flask-cors", "Pillow"]
# badfiles # mp3val and flac # badfiles # mp3val and flac
beatport = ["requests-oauthlib"] beatport = ["requests-oauthlib"]