From a3c8d566f8669c05df0121b74255fe837e50780d Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 30 Nov 2024 16:26:31 +0100 Subject: [PATCH] expand ruff linting --- pyproject.toml | 8 +++++++- scripts/release.py | 10 ++++++---- scripts/towncrier-draft-to-file.py | 2 +- src/pluggy/_callers.py | 6 ++---- src/pluggy/_hooks.py | 3 ++- testing/benchmark.py | 10 ++++++---- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3baa556c..7e7033f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,8 +48,14 @@ package-data = {"pluggy" = ["py.typed"]} [tool.ruff.lint] extend-select = [ "I", # isort - "UP", + "F","E", "W", + "UP", "ANN", ] +extend-ignore = ["ANN101", "ANN102", "ANN401"] + +[tool.ruff.lint.extend-per-file-ignores] +"testing/*.py" = ["ANN001", "ANN002", "ANN003", "ANN201", "ANN202","ANN204" ,] +"docs/*.py" = ["ANN001", "ANN002", "ANN003", "ANN201", "ANN202","ANN204" ,] [tool.ruff.lint.isort] force-single-line = true diff --git a/scripts/release.py b/scripts/release.py index 879d35df..84dc4675 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -12,7 +12,7 @@ from git import Repo -def create_branch(version): +def create_branch(version: str) -> Repo: """Create a fresh branch from upstream/main""" repo = Repo.init(".") if repo.is_dirty(untracked_files=True): @@ -36,7 +36,7 @@ def get_upstream(repo: Repo) -> Remote: raise RuntimeError("could not find pytest-dev/pluggy remote") -def pre_release(version): +def pre_release(version: str) -> None: """Generates new docs, release announcements and creates a local tag.""" create_branch(version) changelog(version, write_out=True) @@ -47,7 +47,7 @@ def pre_release(version): print(f"{Fore.GREEN}Please push your branch to your fork and open a PR.") -def changelog(version, write_out=False): +def changelog(version: str, write_out: bool = False) -> None: if write_out: addopts = [] else: @@ -56,7 +56,7 @@ def changelog(version, write_out=False): check_call(["towncrier", "build", "--yes", "--version", version] + addopts) -def main(): +def main() -> int: init(autoreset=True) parser = argparse.ArgumentParser() parser.add_argument("version", help="Release version") @@ -66,6 +66,8 @@ def main(): except RuntimeError as e: print(f"{Fore.RED}ERROR: {e}") return 1 + else: + return 0 if __name__ == "__main__": diff --git a/scripts/towncrier-draft-to-file.py b/scripts/towncrier-draft-to-file.py index a47caa8f..63b9434c 100644 --- a/scripts/towncrier-draft-to-file.py +++ b/scripts/towncrier-draft-to-file.py @@ -2,7 +2,7 @@ import sys -def main(): +def main() -> int: """ Platform agnostic wrapper script for towncrier. Fixes the issue (pytest#7251) where windows users are unable to natively diff --git a/src/pluggy/_callers.py b/src/pluggy/_callers.py index 7c33710a..48d9f996 100644 --- a/src/pluggy/_callers.py +++ b/src/pluggy/_callers.py @@ -6,9 +6,9 @@ from collections.abc import Generator from collections.abc import Mapping +from collections.abc import Sequence from typing import cast from typing import NoReturn -from typing import Sequence import warnings from ._hooks import HookImpl @@ -50,9 +50,7 @@ def run_legacy_hookwrapper( def _raise_wrapfail( - wrap_controller: ( - Generator[None, Result[object], None] | Generator[None, object, object] - ), + wrap_controller: Generator[None, object, object], msg: str, ) -> NoReturn: co = wrap_controller.gi_code diff --git a/src/pluggy/_hooks.py b/src/pluggy/_hooks.py index 15f2c6dc..cb66640f 100644 --- a/src/pluggy/_hooks.py +++ b/src/pluggy/_hooks.py @@ -483,7 +483,8 @@ def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None: notincall = ", ".join( repr(argname) for argname in self.spec.argnames - # Avoid self.spec.argnames - kwargs.keys() - doesn't preserve order. + # Avoid self.spec.argnames - kwargs.keys() + # it doesn't preserve order. if argname not in kwargs.keys() ) warnings.warn( diff --git a/testing/benchmark.py b/testing/benchmark.py index d13e50aa..cc3be4eb 100644 --- a/testing/benchmark.py +++ b/testing/benchmark.py @@ -2,6 +2,8 @@ Benchmarking and performance tests. """ +from typing import Any + import pytest from pluggy import HookimplMarker @@ -26,16 +28,16 @@ def wrapper(arg1, arg2, arg3): @pytest.fixture(params=[10, 100], ids="hooks={}".format) -def hooks(request): +def hooks(request: Any) -> list[object]: return [hook for i in range(request.param)] @pytest.fixture(params=[10, 100], ids="wrappers={}".format) -def wrappers(request): +def wrappers(request: Any) -> list[object]: return [wrapper for i in range(request.param)] -def test_hook_and_wrappers_speed(benchmark, hooks, wrappers): +def test_hook_and_wrappers_speed(benchmark, hooks, wrappers) -> None: def setup(): hook_name = "foo" hook_impls = [] @@ -65,7 +67,7 @@ def setup(): (100, 100, 0), ], ) -def test_call_hook(benchmark, plugins, wrappers, nesting): +def test_call_hook(benchmark, plugins, wrappers, nesting) -> None: pm = PluginManager("example") class HookSpec: