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 17, 2024
1 parent f31fc4c commit dff3e3f
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 21 deletions.
8 changes: 5 additions & 3 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
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 Any, Callable, NamedTuple, TypeVar, cast, TYPE_CHECKING

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:

Check failure on line 30 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/autotag/hooks.py:17:1: I001 Import block is un-sorted or un-formatted
from beets.library import Item
from collections.abc import Iterable, Iterator

Check failure on line 33 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/autotag/hooks.py:31:1: I001 Import block is un-sorted or un-formatted
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 Any, NamedTuple, TypeVar, Union, cast, TYPE_CHECKING

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:

Check failure on line 40 in beets/autotag/match.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/autotag/match.py:19:1: I001 Import block is un-sorted or un-formatted
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 Any, AnyStr, Callable, Generic, TypeVar, cast, TYPE_CHECKING

from unidecode import unidecode

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

if TYPE_CHECKING:

Check failure on line 47 in beets/dbcore/db.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/dbcore/db.py:17:1: I001 Import block is un-sorted or un-formatted
from types import TracebackType


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

import itertools
import re
from collections.abc import Collection, Sequence

from . import Model, query
from .query import Sort
from typing import TYPE_CHECKING

if TYPE_CHECKING:

Check failure on line 25 in beets/dbcore/queryparse.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/dbcore/queryparse.py:17:1: I001 Import block is un-sorted or un-formatted
from .query import Sort
from collections.abc import Collection, Sequence

Check failure on line 28 in beets/dbcore/queryparse.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beets/dbcore/queryparse.py:26:1: I001 Import block is un-sorted or un-formatted
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 @@ -19,10 +19,13 @@

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
from typing import TYPE_CHECKING

if TYPE_CHECKING:

Check failure on line 26 in beetsplug/autobpm.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beetsplug/autobpm.py:16:1: I001 Import block is un-sorted or un-formatted
from beets.library import Item, Library
from beets.importer import ImportTask

Check failure on line 29 in beetsplug/autobpm.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beetsplug/autobpm.py:27:1: I001 Import block is un-sorted or un-formatted

class AutoBPMPlugin(BeetsPlugin):
Expand Down
16 changes: 9 additions & 7 deletions beetsplug/replaygain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,31 @@
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 typing import Any, Callable, TypeVar, cast, TYPE_CHECKING

from confuse import ConfigView

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:

Check failure on line 38 in beetsplug/replaygain.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beetsplug/replaygain.py:16:1: I001 Import block is un-sorted or un-formatted
from confuse import ConfigView
from beets.importer import ImportSession, ImportTask
from beets.library import Album, Item, Library
from logging import Logger
from collections.abc import Sequence
import optparse

Check failure on line 45 in beetsplug/replaygain.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (I001)

beetsplug/replaygain.py:39:1: I001 Import block is un-sorted or un-formatted
# 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 Callable, TYPE_CHECKING

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 dff3e3f

Please sign in to comment.