diff --git a/dev/make-release-notes.py b/dev/make-release-notes.py index 0c9882c2..0bfc0612 100755 --- a/dev/make-release-notes.py +++ b/dev/make-release-notes.py @@ -31,7 +31,7 @@ def check(name, text): print("*" * 60) print(text) print("*" * 60) - response = input("Accept this %s (Y/n)? " % name).strip().lower() + response = input(f"Accept this {name} (Y/n)? ").strip().lower() if response and response != "y": sys.exit(1) diff --git a/pyproject.toml b/pyproject.toml index 117c7fc8..66b9e52a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,16 +22,19 @@ indent-width = 4 target-version = "py38" [tool.ruff.lint] -# ruff enables Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# ruff enables Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. select = [ - "F", # pyflakes - "E4", "E7", "E9", # pycodestyle "B", # flake8-bugbear "C4", # comprehensions + "E", # pycodestyle + "F", # pyflakes + "I001", # isort + "SIM", # flake8-simplify "UP", # pyupgrade ] ignore = [ "C408", # unnecessary dict call + "SIM115", # Use context handler for opening files ] # Allow fix for all enabled rules (when `--fix`) is provided. diff --git a/tests/test_config.py b/tests/test_config.py index 2d55612b..6209fa11 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -2,19 +2,19 @@ Unit tests for config file and CLI argument parsing. """ -from io import BytesIO import pathlib +from io import BytesIO from textwrap import dedent import pytest from vulture.config import ( DEFAULTS, + InputError, _check_input_config, _parse_args, _parse_toml, make_config, - InputError, ) diff --git a/tests/test_encoding.py b/tests/test_encoding.py index 560a6e5a..88b4c6f6 100644 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -1,8 +1,9 @@ import codecs -from . import v from vulture.utils import ExitCode +from . import v + assert v # Silence pyflakes. diff --git a/tests/test_errors.py b/tests/test_errors.py index 87feff43..17bbffe3 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -1,8 +1,9 @@ import pytest -from . import v, call_vulture from vulture.utils import ExitCode +from . import call_vulture, v + assert v # Silence pyflakes. diff --git a/tests/test_noqa.py b/tests/test_noqa.py index 7b364ad8..5ce96724 100644 --- a/tests/test_noqa.py +++ b/tests/test_noqa.py @@ -2,6 +2,7 @@ from vulture.core import ERROR_CODES from vulture.noqa import NOQA_CODE_MAP, NOQA_REGEXP, _parse_error_codes + from . import check, v assert v # Silence pyflakes. diff --git a/tests/test_reachability.py b/tests/test_reachability.py index a7eb24a3..e0f8f359 100644 --- a/tests/test_reachability.py +++ b/tests/test_reachability.py @@ -1,5 +1,4 @@ -from . import check_multiple_unreachable, check_unreachable -from . import v +from . import check_multiple_unreachable, check_unreachable, v assert v # Silence pyflakes diff --git a/tests/test_scavenging.py b/tests/test_scavenging.py index 71d762f1..3095978e 100644 --- a/tests/test_scavenging.py +++ b/tests/test_scavenging.py @@ -2,9 +2,10 @@ import pytest -from . import check, v from vulture.utils import ExitCode +from . import check, v + assert v # Silence pyflakes. diff --git a/tests/test_script.py b/tests/test_script.py index 5723addb..6b417434 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -3,9 +3,10 @@ import subprocess import sys -from . import call_vulture, REPO, WHITELISTS from vulture.utils import ExitCode +from . import REPO, WHITELISTS, call_vulture + def test_module_with_explicit_whitelists(): assert call_vulture(["vulture/"] + WHITELISTS) == ExitCode.NoDeadCode diff --git a/vulture/core.py b/vulture/core.py index 5b7db43a..cc301b71 100644 --- a/vulture/core.py +++ b/vulture/core.py @@ -1,21 +1,18 @@ import ast -from fnmatch import fnmatch, fnmatchcase -from functools import partial -from pathlib import Path import pkgutil import re import string import sys +from fnmatch import fnmatch, fnmatchcase +from functools import partial +from pathlib import Path from typing import List -from vulture import lines -from vulture import noqa -from vulture import utils +from vulture import lines, noqa, utils from vulture.config import InputError, make_config from vulture.reachability import Reachability from vulture.utils import ExitCode - DEFAULT_CONFIDENCE = 60 IGNORED_VARIABLE_NAMES = {"object", "self"} @@ -161,12 +158,9 @@ def get_report(self, add_size=False): size_report = f", {self.size:d} {line_format}" else: size_report = "" - return "{}:{:d}: {} ({}% confidence{})".format( - utils.format_path(self.filename), - self.first_lineno, - self.message, - self.confidence, - size_report, + return ( + f"{utils.format_path(self.filename)}:{self.first_lineno:d}: " + f"{self.message} ({self.confidence}% confidence{size_report})" ) def get_whitelist_string(self): @@ -177,8 +171,9 @@ def get_whitelist_string(self): prefix = "" if self.typ in ["attribute", "method", "property"]: prefix = "_." - return "{}{} # unused {} ({}:{:d})".format( - prefix, self.name, self.typ, filename, self.first_lineno + return ( + f"{prefix}{self.name} # unused {self.typ} " + f"({filename}:{self.first_lineno:d})" ) def _tuple(self): diff --git a/vulture/noqa.py b/vulture/noqa.py index 4fb3057a..471f0f95 100644 --- a/vulture/noqa.py +++ b/vulture/noqa.py @@ -1,5 +1,5 @@ -from collections import defaultdict import re +from collections import defaultdict NOQA_REGEXP = re.compile( # Use the same regex as flake8 does. diff --git a/vulture/utils.py b/vulture/utils.py index 3382dca3..a3a40fd8 100644 --- a/vulture/utils.py +++ b/vulture/utils.py @@ -1,8 +1,8 @@ import ast -from enum import IntEnum import pathlib import sys import tokenize +from enum import IntEnum class VultureInputException(Exception): diff --git a/vulture/whitelists/ctypes_whitelist.py b/vulture/whitelists/ctypes_whitelist.py index 42fed2d7..294bf710 100644 --- a/vulture/whitelists/ctypes_whitelist.py +++ b/vulture/whitelists/ctypes_whitelist.py @@ -1,5 +1,4 @@ -from ctypes import _CFuncPtr -from ctypes import _Pointer +from ctypes import _CFuncPtr, _Pointer _CFuncPtr.argtypes _CFuncPtr.errcheck diff --git a/vulture/whitelists/unittest_whitelist.py b/vulture/whitelists/unittest_whitelist.py index d68e0b55..121fc4a0 100644 --- a/vulture/whitelists/unittest_whitelist.py +++ b/vulture/whitelists/unittest_whitelist.py @@ -1,4 +1,4 @@ -from unittest import mock, TestCase +from unittest import TestCase, mock TestCase.setUp TestCase.tearDown