Skip to content

Commit

Permalink
Move imports required for typing under the TYPE_CHECKING block
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Nov 23, 2024
1 parent 1653916 commit 971ca5e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 22 deletions.
9 changes: 6 additions & 3 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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

Expand All @@ -35,9 +35,11 @@
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
Expand Down
6 changes: 4 additions & 2 deletions beets/dbcore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
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

Expand All @@ -45,6 +44,9 @@
TrueQuery,
)

if TYPE_CHECKING:
from types import TracebackType


class DBAccessError(Exception):
"""The SQLite database became inaccessible.
Expand Down
8 changes: 6 additions & 2 deletions beets/dbcore/queryparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

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.
Expand Down
2 changes: 1 addition & 1 deletion beets/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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
Expand All @@ -50,6 +49,7 @@
from beets.util import hidden

if TYPE_CHECKING:
from collections.abc import Iterator, Sequence
from logging import Logger

if sys.version_info >= (3, 10):
Expand Down
7 changes: 5 additions & 2 deletions beetsplug/autobpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 11 additions & 8 deletions beetsplug/replaygain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@
import collections
import enum
import math
import optparse
import os
import queue
import signal
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.


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ select = [
"PT", # flake8-pytest-style
# "RUF", # ruff
# "UP", # pyupgrade
"TCH", # flake8-type-checking
"W", # pycodestyle
]
[tool.ruff.lint.per-file-ignores]
Expand Down
6 changes: 4 additions & 2 deletions test/plugins/test_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
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"
Expand Down

0 comments on commit 971ca5e

Please sign in to comment.