Skip to content

Commit

Permalink
Remove some lint exclusions and fix the issues
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Sep 18, 2024
1 parent 0b3dc5a commit 22566b7
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 125 deletions.
2 changes: 1 addition & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def __init__(self):
self.tracks: Dict[TrackInfo, Distance] = {}

@cached_classproperty
def _weights(cls) -> Dict[str, float]: # noqa: N805
def _weights(cls) -> Dict[str, float]:
"""A dictionary from keys to floating-point weights."""
weights_view = config["match"]["distance_weights"]
weights = {}
Expand Down
4 changes: 2 additions & 2 deletions beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import datetime
import re
from enum import IntEnum
from typing import (
Any,
Dict,
Expand Down Expand Up @@ -47,7 +48,6 @@
)
from beets.library import Item
from beets.util import plurality
from beets.util.enumeration import OrderedEnum

# Artist signals that indicate "various artists". These are used at the
# album level to determine whether a given release is likely a VA
Expand All @@ -62,7 +62,7 @@
# Recommendation enumeration.


class Recommendation(OrderedEnum):
class Recommendation(IntEnum):
"""Indicates a qualitative suggestion to the user about what should
be done with a given match.
"""
Expand Down
16 changes: 15 additions & 1 deletion beets/dbcore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@
)
from .types import Type

# flake8: noqa
__all__ = [
"AndQuery",
"Database",
"FieldQuery",
"InvalidQueryError",
"MatchQuery",
"Model",
"OrQuery",
"Query",
"Results",
"Type",
"parse_sorted_query",
"query_from_strings",
"sort_from_strings",
]
43 changes: 32 additions & 11 deletions beets/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,34 @@
calls (`debug`, `info`, etc).
"""

import logging
import threading
from copy import copy
from logging import (
DEBUG,
INFO,
NOTSET,
WARNING,
FileHandler,
Filter,
Handler,
Logger,
NullHandler,
StreamHandler,
)

__all__ = [
"DEBUG",
"INFO",
"NOTSET",
"WARNING",
"FileHandler",
"Filter",
"Handler",
"Logger",
"NullHandler",
"StreamHandler",
"getLogger",
]


def logsafe(val):
Expand All @@ -45,7 +70,7 @@ def logsafe(val):
return val


class StrFormatLogger(logging.Logger):
class StrFormatLogger(Logger):
"""A version of `Logger` that uses `str.format`-style formatting
instead of %-style formatting and supports keyword arguments.
Expand Down Expand Up @@ -95,12 +120,12 @@ def _log(
)


class ThreadLocalLevelLogger(logging.Logger):
class ThreadLocalLevelLogger(Logger):
"""A version of `Logger` whose level is thread-local instead of shared."""

def __init__(self, name, level=logging.NOTSET):
def __init__(self, name, level=NOTSET):
self._thread_level = threading.local()
self.default_level = logging.NOTSET
self.default_level = NOTSET
super().__init__(name, level)

@property
Expand All @@ -127,17 +152,13 @@ class BeetsLogger(ThreadLocalLevelLogger, StrFormatLogger):
pass


my_manager = copy(logging.Logger.manager)
my_manager = copy(Logger.manager)
my_manager.loggerClass = BeetsLogger


# Act like the stdlib logging module by re-exporting its namespace.
from logging import * # noqa


# Override the `getLogger` to use our machinery.
def getLogger(name=None): # noqa
if name:
return my_manager.getLogger(name)
else:
return logging.Logger.root
return Logger.root
8 changes: 4 additions & 4 deletions beets/test/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ def import_session(lib=None, loghandler=None, paths=[], query=[], cli=False):
class Assertions:
"""A mixin with additional unit test assertions."""

def assertExists(self, path): # noqa
def assertExists(self, path):
assert os.path.exists(syspath(path)), f"file does not exist: {path!r}"

def assertNotExists(self, path): # noqa
def assertNotExists(self, path):
assert not os.path.exists(syspath(path)), f"file exists: {path!r}"

def assertIsFile(self, path): # noqa
def assertIsFile(self, path):
self.assertExists(path)
assert os.path.isfile(
syspath(path)
), "path exists, but is not a regular file: {!r}".format(path)

def assertIsDir(self, path): # noqa
def assertIsDir(self, path):
self.assertExists(path)
assert os.path.isdir(
syspath(path)
Expand Down
2 changes: 1 addition & 1 deletion beets/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def par_map(transform: Callable, items: Iterable):
pool.join()


class cached_classproperty: # noqa: N801
class cached_classproperty:
"""A decorator implementing a read-only property that is *lazy* in
the sense that the getter is only invoked once. Subsequent accesses
through *any* instance use the cached result.
Expand Down
42 changes: 0 additions & 42 deletions beets/util/enumeration.py

This file was deleted.

10 changes: 0 additions & 10 deletions beetsplug/bpd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,16 +736,6 @@ def cmd_seekid(self, conn, track_id, pos):
index = self._id_to_index(track_id)
return self.cmd_seek(conn, index, pos)

# Additions to the MPD protocol.

def cmd_crash_TypeError(self, conn): # noqa: N802
"""Deliberately trigger a TypeError for testing purposes.
We want to test that the server properly responds with ERROR_SYSTEM
without crashing, and that this is not treated as ERROR_ARG (since it
is caused by a programming error, not a protocol error).
"""
"a" + 2


class Connection:
"""A connection between a client and the server."""
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,4 @@ ignore-variadic-names = true

[tool.ruff.lint.pep8-naming]
classmethod-decorators = ["cached_classproperty"]
extend-ignore-names = ["assert*", "cached_classproperty"]
22 changes: 11 additions & 11 deletions test/plugins/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def tearDown(self):
fetchart.FileSystem.get = self.old_fs_source_get
super().tearDown()

def _assertImageIsValidArt(self, image_file, should_exist): # noqa
def assertImageIsValidArt(self, image_file, should_exist):
self.assertExists(image_file)
self.image_file = image_file

Expand Down Expand Up @@ -892,42 +892,42 @@ def _require_backend(self):
def test_respect_minwidth(self):
self._require_backend()
self.plugin.minwidth = 300
self._assertImageIsValidArt(self.IMG_225x225, False)
self._assertImageIsValidArt(self.IMG_348x348, True)
self.assertImageIsValidArt(self.IMG_225x225, False)
self.assertImageIsValidArt(self.IMG_348x348, True)

def test_respect_enforce_ratio_yes(self):
self._require_backend()
self.plugin.enforce_ratio = True
self._assertImageIsValidArt(self.IMG_500x490, False)
self._assertImageIsValidArt(self.IMG_225x225, True)
self.assertImageIsValidArt(self.IMG_500x490, False)
self.assertImageIsValidArt(self.IMG_225x225, True)

def test_respect_enforce_ratio_no(self):
self.plugin.enforce_ratio = False
self._assertImageIsValidArt(self.IMG_500x490, True)
self.assertImageIsValidArt(self.IMG_500x490, True)

def test_respect_enforce_ratio_px_above(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_px = 5
self._assertImageIsValidArt(self.IMG_500x490, False)
self.assertImageIsValidArt(self.IMG_500x490, False)

def test_respect_enforce_ratio_px_below(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_px = 15
self._assertImageIsValidArt(self.IMG_500x490, True)
self.assertImageIsValidArt(self.IMG_500x490, True)

def test_respect_enforce_ratio_percent_above(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_percent = (500 - 490) / 500 * 0.5
self._assertImageIsValidArt(self.IMG_500x490, False)
self.assertImageIsValidArt(self.IMG_500x490, False)

def test_respect_enforce_ratio_percent_below(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_percent = (500 - 490) / 500 * 1.5
self._assertImageIsValidArt(self.IMG_500x490, True)
self.assertImageIsValidArt(self.IMG_500x490, True)

def test_resize_if_necessary(self):
self._require_backend()
Expand All @@ -944,7 +944,7 @@ def test_fileresize_if_necessary(self):
self._require_backend()
self.plugin.max_filesize = self.IMG_225x225_SIZE
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, False)
self._assertImageIsValidArt(self.IMG_225x225, True)
self.assertImageIsValidArt(self.IMG_225x225, True)

def test_fileresize_no_scale(self):
self._require_backend()
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tagged_copy_cmd(self, tag):
shell_quote(sys.executable), shell_quote(stub), tag
)

def assertFileTag(self, path, tag): # noqa
def assertFileTag(self, path, tag):
"""Assert that the path is a file and the files content ends
with `tag`.
"""
Expand All @@ -68,7 +68,7 @@ def assertFileTag(self, path, tag): # noqa
f.read() == tag
), f"{displayable_path(path)} is not tagged with {display_tag}"

def assertNoFileTag(self, path, tag): # noqa
def assertNoFileTag(self, path, tag):
"""Assert that the path is a file and the files content does not
end with `tag`.
"""
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class EditMixin(PluginMixin):

plugin = "edit"

def assertItemFieldsModified( # noqa
def assertItemFieldsModified(
self, library_items, items, fields=[], allowed=["path"]
):
"""Assert that items in the library (`lib_items`) have different values
Expand Down Expand Up @@ -134,7 +134,7 @@ def setUp(self):
{f: item[f] for f in item._fields} for item in self.album.items()
]

def assertCounts( # noqa
def assertCounts(
self,
mock_write,
album_count=ALBUM_COUNT,
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/test_importadded.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def find_media_file(self, item):
"No MediaFile found for Item " + displayable_path(item.path)
)

def assertEqualTimes(self, first, second, msg=None): # noqa
def assertEqualTimes(self, first, second, msg=None):
"""For comparing file modification times at a sufficient precision"""
assert first == pytest.approx(second, rel=1e-4), msg

def assertAlbumImport(self): # noqa
def assertAlbumImport(self):
self.importer.run()
album = self.lib.albums().get()
assert album.added == self.min_mtime
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_stat(v):
for path in dirs_in_library(self.lib.directory, item.path):
self.assertPerms(path, "dir", expect_success)

def assertPerms(self, path, typ, expect_success): # noqa
def assertPerms(self, path, typ, expect_success):
for x in [
(True, self.exp_perms[expect_success][typ], "!="),
(False, self.exp_perms[not expect_success][typ], "=="),
Expand Down
Loading

0 comments on commit 22566b7

Please sign in to comment.