Skip to content

Commit

Permalink
expand ruff linting
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Nov 30, 2024
1 parent ea049ed commit 4c28878
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,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
Expand Down
10 changes: 6 additions & 4 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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")
Expand All @@ -66,6 +66,8 @@ def main():
except RuntimeError as e:
print(f"{Fore.RED}ERROR: {e}")
return 1
else:
return 0


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/towncrier-draft-to-file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,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(
Expand Down
10 changes: 6 additions & 4 deletions testing/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Benchmarking and performance tests.
"""

from typing import Any

import pytest

from pluggy import HookimplMarker
Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4c28878

Please sign in to comment.