From 59664be90c4b96dd4187cf93f4146cda155b4bf4 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 7 Dec 2024 09:20:04 -0300 Subject: [PATCH] Run pre-commit (with pyupgrade) on all files --- src/pluggy/_callers.py | 9 ++++----- src/pluggy/_hooks.py | 16 +++++++--------- src/pluggy/_manager.py | 6 +++--- src/pluggy/_result.py | 4 +--- src/pluggy/_tracing.py | 5 ++--- testing/test_hookcaller.py | 7 +++---- testing/test_invocations.py | 2 +- testing/test_multicall.py | 12 +++++------- testing/test_pluginmanager.py | 5 ++--- testing/test_tracer.py | 4 +--- 10 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/pluggy/_callers.py b/src/pluggy/_callers.py index 3ac24212..935cb370 100644 --- a/src/pluggy/_callers.py +++ b/src/pluggy/_callers.py @@ -4,12 +4,11 @@ from __future__ import annotations +from collections.abc import Generator +from collections.abc import Mapping +from collections.abc import Sequence from typing import cast -from typing import Generator -from typing import Mapping from typing import NoReturn -from typing import Sequence -from typing import Tuple from typing import Union import warnings @@ -22,7 +21,7 @@ # Need to distinguish between old- and new-style hook wrappers. # Wrapping with a tuple is the fastest type-safe way I found to do it. Teardown = Union[ - Tuple[Generator[None, Result[object], None], HookImpl], + tuple[Generator[None, Result[object], None], HookImpl], Generator[None, object, object], ] diff --git a/src/pluggy/_hooks.py b/src/pluggy/_hooks.py index a81d2b28..15f2c6dc 100644 --- a/src/pluggy/_hooks.py +++ b/src/pluggy/_hooks.py @@ -4,21 +4,19 @@ from __future__ import annotations +from collections.abc import Generator +from collections.abc import Mapping +from collections.abc import Sequence +from collections.abc import Set import inspect import sys from types import ModuleType -from typing import AbstractSet from typing import Any from typing import Callable from typing import Final from typing import final -from typing import Generator -from typing import List -from typing import Mapping from typing import Optional from typing import overload -from typing import Sequence -from typing import Tuple from typing import TYPE_CHECKING from typing import TypedDict from typing import TypeVar @@ -34,7 +32,7 @@ _Plugin = object _HookExec = Callable[ [str, Sequence["HookImpl"], Mapping[str, object], bool], - Union[object, List[object]], + Union[object, list[object]], ] _HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]] @@ -376,7 +374,7 @@ def __getattr__(self, name: str) -> HookCaller: ... _HookRelay = HookRelay -_CallHistory = List[Tuple[Mapping[str, object], Optional[Callable[[Any], None]]]] +_CallHistory = list[tuple[Mapping[str, object], Optional[Callable[[Any], None]]]] class HookCaller: @@ -608,7 +606,7 @@ class _SubsetHookCaller(HookCaller): "_remove_plugins", ) - def __init__(self, orig: HookCaller, remove_plugins: AbstractSet[_Plugin]) -> None: + def __init__(self, orig: HookCaller, remove_plugins: Set[_Plugin]) -> None: self._orig = orig self._remove_plugins = remove_plugins self.name = orig.name # type: ignore[misc] diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index d778334b..2f57270d 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -1,14 +1,14 @@ from __future__ import annotations +from collections.abc import Iterable +from collections.abc import Mapping +from collections.abc import Sequence import inspect import types from typing import Any from typing import Callable from typing import cast from typing import Final -from typing import Iterable -from typing import Mapping -from typing import Sequence from typing import TYPE_CHECKING import warnings diff --git a/src/pluggy/_result.py b/src/pluggy/_result.py index aa3912c0..656a5841 100644 --- a/src/pluggy/_result.py +++ b/src/pluggy/_result.py @@ -10,12 +10,10 @@ from typing import final from typing import Generic from typing import Optional -from typing import Tuple -from typing import Type from typing import TypeVar -_ExcInfo = Tuple[Type[BaseException], BaseException, Optional[TracebackType]] +_ExcInfo = tuple[type[BaseException], BaseException, Optional[TracebackType]] ResultType = TypeVar("ResultType") diff --git a/src/pluggy/_tracing.py b/src/pluggy/_tracing.py index cd238ad7..f0b36db1 100644 --- a/src/pluggy/_tracing.py +++ b/src/pluggy/_tracing.py @@ -4,14 +4,13 @@ from __future__ import annotations +from collections.abc import Sequence from typing import Any from typing import Callable -from typing import Sequence -from typing import Tuple _Writer = Callable[[str], object] -_Processor = Callable[[Tuple[str, ...], Tuple[Any, ...]], object] +_Processor = Callable[[tuple[str, ...], tuple[Any, ...]], object] class TagTracer: diff --git a/testing/test_hookcaller.py b/testing/test_hookcaller.py index 3db76de2..032d5c7b 100644 --- a/testing/test_hookcaller.py +++ b/testing/test_hookcaller.py @@ -1,7 +1,6 @@ +from collections.abc import Generator +from collections.abc import Sequence from typing import Callable -from typing import Generator -from typing import List -from typing import Sequence from typing import TypeVar import pytest @@ -63,7 +62,7 @@ def addmeth(hc: HookCaller) -> AddMeth: return AddMeth(hc) -def funcs(hookmethods: Sequence[HookImpl]) -> List[Callable[..., object]]: +def funcs(hookmethods: Sequence[HookImpl]) -> list[Callable[..., object]]: return [hookmethod.function for hookmethod in hookmethods] diff --git a/testing/test_invocations.py b/testing/test_invocations.py index 833ec2b7..779a1ce3 100644 --- a/testing/test_invocations.py +++ b/testing/test_invocations.py @@ -1,4 +1,4 @@ -from typing import Iterator +from collections.abc import Iterator import pytest diff --git a/testing/test_multicall.py b/testing/test_multicall.py index eb81230b..c7ed0235 100644 --- a/testing/test_multicall.py +++ b/testing/test_multicall.py @@ -1,8 +1,6 @@ +from collections.abc import Mapping +from collections.abc import Sequence from typing import Callable -from typing import List -from typing import Mapping -from typing import Sequence -from typing import Type from typing import Union import pytest @@ -22,7 +20,7 @@ def MC( methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object], firstresult: bool = False, -) -> Union[object, List[object]]: +) -> Union[object, list[object]]: caller = _multicall hookfuncs = [] for method in methods: @@ -250,7 +248,7 @@ def m1(): @pytest.mark.parametrize("exc", [ValueError, SystemExit]) -def test_hookwrapper_exception(exc: "Type[BaseException]") -> None: +def test_hookwrapper_exception(exc: type[BaseException]) -> None: out = [] @hookimpl(hookwrapper=True) @@ -320,7 +318,7 @@ def m4(): @pytest.mark.parametrize("exc", [ValueError, SystemExit]) -def test_wrapper_exception(exc: "Type[BaseException]") -> None: +def test_wrapper_exception(exc: type[BaseException]) -> None: out = [] @hookimpl(wrapper=True) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index c4ce08f3..46c96780 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -4,7 +4,6 @@ import importlib.metadata from typing import Any -from typing import List import pytest @@ -606,7 +605,7 @@ def my_distributions(): def test_add_tracefuncs(he_pm: PluginManager) -> None: - out: List[Any] = [] + out: list[Any] = [] class api1: @hookimpl @@ -659,7 +658,7 @@ def he_method1(self): raise ValueError() he_pm.register(api1()) - out: List[Any] = [] + out: list[Any] = [] he_pm.trace.root.setwriter(out.append) undo = he_pm.enable_tracing() try: diff --git a/testing/test_tracer.py b/testing/test_tracer.py index 5e538369..c90c78f1 100644 --- a/testing/test_tracer.py +++ b/testing/test_tracer.py @@ -1,5 +1,3 @@ -from typing import List - import pytest from pluggy._tracing import TagTracer @@ -13,7 +11,7 @@ def rootlogger() -> TagTracer: def test_simple(rootlogger: TagTracer) -> None: log = rootlogger.get("pytest") log("hello") - out: List[str] = [] + out: list[str] = [] rootlogger.setwriter(out.append) log("world") assert len(out) == 1