From f51d5249d23634b85fa536eba07da6d82b2fa579 Mon Sep 17 00:00:00 2001 From: Konstantin <78656278+amogus07@users.noreply.github.com> Date: Tue, 27 Aug 2024 06:51:42 +0000 Subject: [PATCH] Revert "fixed + improved typing in some places" This reverts commit 647d6ab29a1fb1a2334669f81b7bb0e53e6a3af3. --- beets/autotag/match.py | 2 +- beets/dbcore/db.py | 2 +- beets/plugins.py | 3 +-- beets/util/__init__.py | 20 ++++++++------------ 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 3dfb27ba9..f6d58f5bc 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -78,7 +78,7 @@ class Recommendation(OrderedEnum): class Proposal(NamedTuple): - candidates: Sequence[Union[AlbumMatch, TrackMatch]] + candidates: Sequence[AlbumMatch | TrackMatch] recommendation: Recommendation diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index 70e1562f9..566c11631 100755 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -322,7 +322,7 @@ class Model(ABC): """ @cached_classproperty - def _relation(cls) -> Model: + def _relation(cls) -> type[Model]: """The model that this model is closely related to.""" return cls diff --git a/beets/plugins.py b/beets/plugins.py index c965d4b0e..35995c341 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -21,7 +21,6 @@ import re import traceback from collections import defaultdict from functools import wraps -from typing import Any, Dict import mediafile @@ -292,7 +291,7 @@ def load_plugins(names=()): ) -_instances: Dict[Any, Any] = {} +_instances = {} def find_plugins(): diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 66051f8c1..4f0aa283c 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -298,7 +298,7 @@ def fnmatch_all(names: Sequence[bytes], patterns: Sequence[bytes]) -> bool: def prune_dirs( path: str, root: Optional[Bytes_or_String] = None, - clutter: Sequence[Bytes_or_String] = [".DS_Store", "Thumbs.db"], + clutter: Sequence[str] = (".DS_Store", "Thumbs.db"), ): """If path is an empty directory, then remove it. Recursively remove path's ancestry up to root (which is never removed) where there are @@ -330,7 +330,7 @@ def prune_dirs( if not os.path.exists(directory): # Directory gone already. continue - clutter = [bytestring_path(c) for c in clutter] + clutter: List[bytes] = [bytestring_path(c) for c in clutter] match_paths = [bytestring_path(d) for d in os.listdir(directory)] try: if fnmatch_all(match_paths, clutter): @@ -439,18 +439,14 @@ def displayable_path( return path.decode("utf-8", "ignore") -def syspath(path: Optional[PathLike], prefix: bool = True) -> str: +def syspath(path: PathLike, prefix: bool = True) -> str: """Convert a path for use by the operating system. In particular, paths on Windows must receive a magic prefix and must be converted to Unicode before they are sent to the OS. To disable the magic prefix on Windows, set `prefix` to False---but only do this if you *really* know what you're doing. """ - if path is None: - raise ValueError("The path cannot be None") - str_path = os.fsdecode(path) - # Don't do anything if we're not on windows if os.path.__name__ != "ntpath": return str_path @@ -760,7 +756,7 @@ def legalize_path( length: int, extension: bytes, fragment: bool, -) -> Tuple[Bytes_or_String, bool]: +) -> Tuple[Union[Bytes_or_String, bool]]: """Given a path-like Unicode string, produce a legal path. Return the path and a flag indicating whether some replacements had to be ignored (see below). @@ -827,7 +823,7 @@ def as_string(value: Any) -> str: return str(value) -def plurality(objs: Sequence[T]) -> Tuple[T, int]: +def plurality(objs: Sequence[T]) -> T: """Given a sequence of hashble objects, returns the object that is most common in the set and the its number of appearance. The sequence must contain at least one object. @@ -838,7 +834,7 @@ def plurality(objs: Sequence[T]) -> Tuple[T, int]: return c.most_common(1)[0] -def convert_command_args(args: Sequence[Bytes_or_String]) -> List[str]: +def convert_command_args(args: List[bytes]) -> List[str]: """Convert command arguments, which may either be `bytes` or `str` objects, to uniformly surrogate-escaped strings.""" assert isinstance(args, list) @@ -858,7 +854,7 @@ class CommandOutput(NamedTuple): def command_output( - cmd: Sequence[Bytes_or_String], + cmd: List[Bytes_or_String], shell: bool = False, ) -> CommandOutput: """Runs the command and returns its output after it has exited. @@ -1040,7 +1036,7 @@ def asciify_path(path: str, sep_replace: str) -> str: # if this platform has an os.altsep, change it to os.sep. if os.altsep: path = path.replace(os.altsep, os.sep) - path_components: Sequence[Bytes_or_String] = path.split(os.sep) + path_components: List[Bytes_or_String] = path.split(os.sep) for index, item in enumerate(path_components): path_components[index] = unidecode(item).replace(os.sep, sep_replace) if os.altsep: