Using 3.9 unions instead of new 3.10 style unions for typehints

This commit is contained in:
Sebastian Mohr 2025-02-01 13:25:25 +01:00
parent 435864cb50
commit c81a2c9b18
2 changed files with 17 additions and 18 deletions

View file

@ -14,7 +14,7 @@ from collections import defaultdict
from dataclasses import dataclass
from enum import Enum
from tempfile import mkdtemp
from typing import Iterable, Sequence
from typing import Dict, Iterable, Optional, Sequence, Union
import mediafile
@ -97,7 +97,7 @@ class ImportState:
taghistory: set
path: PathLike
def __init__(self, readonly=False, path: PathLike | None = None):
def __init__(self, readonly=False, path: Union[PathLike, None] = None):
self.path = path or config["statefile"].as_filename()
self._open()
@ -182,19 +182,19 @@ class ImportSession(ABC):
"""
logger: logging.Logger
paths: list[bytes] | None
paths: Union[list[bytes], None]
lib: library.Library
_is_resuming: dict[bytes, bool]
_is_resuming: Dict[bytes, bool]
_merged_items: set
_merged_dirs: set
def __init__(
self,
lib: library.Library,
loghandler: logging.Handler | None,
paths: Iterable[PathLike] | None,
query: dbcore.Query | None,
loghandler: Optional[logging.Handler],
paths: Optional[Sequence[PathLike]],
query: Optional[dbcore.Query],
):
"""Create a session.
@ -223,7 +223,7 @@ class ImportSession(ABC):
else:
self.paths = None
def _setup_logging(self, loghandler: logging.Handler | None):
def _setup_logging(self, loghandler: Optional[logging.Handler]):
logger = logging.getLogger(__name__)
logger.propagate = False
if not loghandler:

View file

@ -22,7 +22,12 @@ import pytest
from beets.library import Item
from beets.test.helper import PluginMixin
from beetsplug import lyrics
try:
from beetsplug import lyrics
except Exception:
pytest.skip("lyrics plugin couldn't be loaded", allow_module_level=True)
from .lyrics_pages import LyricsPage, lyrics_pages
@ -69,9 +74,7 @@ class TestLyricsUtils:
("横山克", "Masaru Yokoyama", ["Masaru Yokoyama"]),
],
)
def test_search_pairs_artists(
self, artist, artist_sort, expected_extra_artists
):
def test_search_pairs_artists(self, artist, artist_sort, expected_extra_artists):
item = Item(artist=artist, artist_sort=artist_sort, title="song")
actual_artists = [a for a, _ in lyrics.search_pairs(item)]
@ -96,9 +99,7 @@ class TestLyricsUtils:
def test_search_pairs_titles(self, title, expected_extra_titles):
item = Item(title=title, artist="A")
actual_titles = {
t: None for _, tit in lyrics.search_pairs(item) for t in tit
}
actual_titles = {t: None for _, tit in lyrics.search_pairs(item) for t in tit}
assert list(actual_titles) == [title, *expected_extra_titles]
@ -240,9 +241,7 @@ class LyricsBackendTest(LyricsPluginMixin):
@pytest.fixture
def lyrics_html(self, lyrics_root_dir, file_name):
return (lyrics_root_dir / f"{file_name}.txt").read_text(
encoding="utf-8"
)
return (lyrics_root_dir / f"{file_name}.txt").read_text(encoding="utf-8")
@pytest.mark.on_lyrics_update