Move imports required for typing under the TYPE_CHECKING block

This commit is contained in:
Šarūnas Nejus 2024-11-22 04:38:50 +00:00
parent 161b0522bb
commit 5c81f94cf7
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
9 changed files with 42 additions and 22 deletions

View file

@ -17,18 +17,21 @@
from __future__ import annotations
import re
from collections.abc import Iterable, Iterator
from functools import total_ordering
from typing import Any, Callable, NamedTuple, TypeVar, cast
from typing import TYPE_CHECKING, Any, Callable, NamedTuple, TypeVar, cast
from jellyfish import levenshtein_distance
from unidecode import unidecode
from beets import config, logging, plugins
from beets.autotag import mb
from beets.library import Item
from beets.util import as_string, cached_classproperty
if TYPE_CHECKING:
from collections.abc import Iterable, Iterator
from beets.library import Item
log = logging.getLogger("beets")
V = TypeVar("V")

View file

@ -22,7 +22,7 @@ import datetime
import re
from collections.abc import Iterable, Sequence
from enum import IntEnum
from typing import Any, NamedTuple, TypeVar, Union, cast
from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar, Union, cast
from munkres import Munkres
@ -35,9 +35,11 @@ from beets.autotag import (
TrackMatch,
hooks,
)
from beets.library import Item
from beets.util import plurality
if TYPE_CHECKING:
from beets.library import Item
# Artist signals that indicate "various artists". These are used at the
# album level to determine whether a given release is likely a VA
# release and also on the track level to to remove the penalty for

View file

@ -26,8 +26,7 @@ from abc import ABC
from collections import defaultdict
from collections.abc import Generator, Iterable, Iterator, Mapping, Sequence
from sqlite3 import Connection
from types import TracebackType
from typing import Any, AnyStr, Callable, Generic, TypeVar, cast
from typing import TYPE_CHECKING, Any, AnyStr, Callable, Generic, TypeVar, cast
from unidecode import unidecode
@ -45,6 +44,9 @@ from .query import (
TrueQuery,
)
if TYPE_CHECKING:
from types import TracebackType
class DBAccessError(Exception):
"""The SQLite database became inaccessible.

View file

@ -18,10 +18,14 @@ from __future__ import annotations
import itertools
import re
from collections.abc import Collection, Sequence
from typing import TYPE_CHECKING
from . import Model, query
from .query import Sort
if TYPE_CHECKING:
from collections.abc import Collection, Sequence
from .query import Sort
PARSE_QUERY_PART_REGEX = re.compile(
# Non-capturing optional segment for the keyword.

View file

@ -28,7 +28,6 @@ import sys
import tempfile
import traceback
from collections import Counter
from collections.abc import Iterator, Sequence
from contextlib import suppress
from enum import Enum
from importlib import import_module
@ -50,6 +49,7 @@ from unidecode import unidecode
from beets.util import hidden
if TYPE_CHECKING:
from collections.abc import Iterator, Sequence
from logging import Logger
if sys.version_info >= (3, 10):

View file

@ -16,14 +16,17 @@
from __future__ import annotations
from collections.abc import Iterable
from typing import TYPE_CHECKING
import librosa
from beets.importer import ImportTask
from beets.library import Item, Library
from beets.plugins import BeetsPlugin
from beets.ui import Subcommand, should_write
if TYPE_CHECKING:
from beets.importer import ImportTask
from beets.library import Item, Library
class AutoBPMPlugin(BeetsPlugin):
def __init__(self) -> None:

View file

@ -18,7 +18,6 @@ from __future__ import annotations
import collections
import enum
import math
import optparse
import os
import queue
import signal
@ -26,21 +25,25 @@ import subprocess
import sys
import warnings
from abc import ABC, abstractmethod
from collections.abc import Sequence
from dataclasses import dataclass
from logging import Logger
from multiprocessing.pool import ThreadPool
from threading import Event, Thread
from typing import Any, Callable, TypeVar, cast
from confuse import ConfigView
from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
from beets import ui
from beets.importer import ImportSession, ImportTask
from beets.library import Album, Item, Library
from beets.plugins import BeetsPlugin
from beets.util import command_output, displayable_path, syspath
if TYPE_CHECKING:
import optparse
from collections.abc import Sequence
from logging import Logger
from confuse import ConfigView
from beets.importer import ImportSession, ImportTask
from beets.library import Album, Item, Library
# Utilities.

View file

@ -255,6 +255,7 @@ select = [
"PT", # flake8-pytest-style
# "RUF", # ruff
# "UP", # pyupgrade
"TCH", # flake8-type-checking
"W", # pycodestyle
]
[tool.ruff.lint.per-file-ignores]

View file

@ -18,13 +18,15 @@ from __future__ import annotations
import os.path
import sys
import unittest
from collections.abc import Iterator
from contextlib import contextmanager
from typing import Callable
from typing import TYPE_CHECKING, Callable
from beets import plugins
from beets.test.helper import PluginTestCase, capture_log
if TYPE_CHECKING:
from collections.abc import Iterator
class HookTestCase(PluginTestCase):
plugin = "hook"