From 078ffc1c579fc917d1afd60d5a970a87996cfc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Sat, 27 Dec 2025 23:38:55 +0000 Subject: [PATCH] Configure ruff for py310 --- beets/dbcore/query.py | 4 ++-- beets/logging.py | 34 ++++++++++++++++----------------- beets/util/__init__.py | 5 ++--- beetsplug/lastgenre/__init__.py | 3 ++- beetsplug/spotify.py | 6 ++---- pyproject.toml | 4 ++-- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index 9556cdf77..52aed43b2 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -25,7 +25,7 @@ from datetime import datetime, timedelta from functools import cached_property, reduce from operator import mul, or_ from re import Pattern -from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union +from typing import TYPE_CHECKING, Any, Generic, TypeVar from beets import util from beets.util.units import raw_seconds_short @@ -124,7 +124,7 @@ class Query(ABC): return hash(type(self)) -SQLiteType = Union[str, bytes, float, int, memoryview, None] +SQLiteType = str | bytes | float | int | memoryview | None AnySQLiteType = TypeVar("AnySQLiteType", bound=SQLiteType) FieldQueryType = type["FieldQuery"] diff --git a/beets/logging.py b/beets/logging.py index ecde9b33d..0fc3a13e7 100644 --- a/beets/logging.py +++ b/beets/logging.py @@ -37,7 +37,23 @@ from logging import ( NullHandler, StreamHandler, ) -from typing import TYPE_CHECKING, Any, TypeVar, Union, overload +from typing import TYPE_CHECKING, Any, TypeVar, overload + +if TYPE_CHECKING: + from collections.abc import Mapping + from logging import RootLogger + from types import TracebackType + + T = TypeVar("T") + + # see https://github.com/python/typeshed/blob/main/stdlib/logging/__init__.pyi + _SysExcInfoType = ( + tuple[type[BaseException], BaseException, TracebackType | None] + | tuple[None, None, None] + ) + _ExcInfoType = _SysExcInfoType | BaseException | bool | None + _ArgsType = tuple[object, ...] | Mapping[str, object] + __all__ = [ "DEBUG", @@ -53,22 +69,6 @@ __all__ = [ "getLogger", ] -if TYPE_CHECKING: - from collections.abc import Mapping - from logging import RootLogger - - T = TypeVar("T") - from types import TracebackType - - # see https://github.com/python/typeshed/blob/main/stdlib/logging/__init__.pyi - _SysExcInfoType = Union[ - tuple[type[BaseException], BaseException, Union[TracebackType, None]], - tuple[None, None, None], - ] - _ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] - _ArgsType = Union[tuple[object, ...], Mapping[str, object]] - - # Regular expression to match: # - C0 control characters (0x00-0x1F) except useful whitespace (\t, \n, \r) # - DEL control character (0x7f) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 10508aaaf..ea08bb65d 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -44,7 +44,6 @@ from typing import ( Generic, NamedTuple, TypeVar, - Union, cast, ) @@ -63,8 +62,8 @@ if TYPE_CHECKING: MAX_FILENAME_LENGTH = 200 WINDOWS_MAGIC_PREFIX = "\\\\?\\" T = TypeVar("T") -PathLike = Union[str, bytes, Path] -StrPath = Union[str, Path] +StrPath = str | Path +PathLike = StrPath | bytes Replacements = Sequence[tuple[Pattern[str], str]] # Here for now to allow for a easy replace later on diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index e622096cf..1bb874c04 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -28,7 +28,7 @@ import os import traceback from functools import singledispatchmethod from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable +from typing import TYPE_CHECKING, Any import pylast import yaml @@ -39,6 +39,7 @@ from beets.util import plurality, unique_list if TYPE_CHECKING: import optparse + from collections.abc import Callable from beets.library import LibModel diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index 4a55dea5d..a778cf1e2 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -27,7 +27,7 @@ import re import threading import time import webbrowser -from typing import TYPE_CHECKING, Any, Literal, Union +from typing import TYPE_CHECKING, Any, Literal import confuse import requests @@ -86,9 +86,7 @@ class AudioFeaturesUnavailableError(Exception): class SpotifyPlugin( - SearchApiMetadataSourcePlugin[ - Union[SearchResponseAlbums, SearchResponseTracks] - ] + SearchApiMetadataSourcePlugin[SearchResponseAlbums | SearchResponseTracks] ): item_types = { "spotify_track_popularity": types.INTEGER, diff --git a/pyproject.toml b/pyproject.toml index 1e98b189a..6cdc19285 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -290,7 +290,7 @@ extend-exclude = [ ] [tool.ruff] -target-version = "py39" +target-version = "py310" line-length = 80 [tool.ruff.lint] @@ -308,7 +308,7 @@ select = [ "PT", # flake8-pytest-style # "RUF", # ruff "UP", # pyupgrade - "TCH", # flake8-type-checking + "TC", # flake8-type-checking "W", # pycodestyle ] ignore = [