Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ jobs:
fail-fast: false
matrix:
name: [
"windows-py39",
"windows-py310",
"windows-py314",
"windows-pypy3",

"ubuntu-py310-pytestmain",
"ubuntu-py39",
"ubuntu-py310",
"ubuntu-py311",
"ubuntu-py312",
Expand All @@ -46,10 +45,10 @@ jobs:
]

include:
- name: "windows-py39"
python: "3.9"
- name: "windows-py310"
python: "3.10"
os: windows-latest
tox_env: "py39"
tox_env: "py310"
- name: "windows-py313"
python: "3.13"
os: windows-latest
Expand All @@ -59,23 +58,19 @@ jobs:
os: windows-latest
tox_env: "py314"
- name: "windows-pypy3"
python: "pypy3.9"
python: "pypy3.10"
os: windows-latest
tox_env: "pypy3"
- name: "ubuntu-py310-pytestmain"
python: "3.10"
os: ubuntu-latest
tox_env: "py310-pytestmain"
use_coverage: true
- name: "ubuntu-py39"
python: "3.9"
os: ubuntu-latest
tox_env: "py39"
use_coverage: true
- name: "ubuntu-py310"
python: "3.10"
os: ubuntu-latest
tox_env: "py310"
use_coverage: true
- name: "ubuntu-py311"
python: "3.11"
os: ubuntu-latest
Expand All @@ -97,12 +92,12 @@ jobs:
tox_env: "py314"
use_coverage: true
- name: "ubuntu-pypy3"
python: "pypy3.9"
python: "pypy3.10"
os: ubuntu-latest
tox_env: "pypy3"
use_coverage: true
- name: "ubuntu-benchmark"
python: "3.9"
python: "3.10"
os: ubuntu-latest
tox_env: "benchmark"

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
rev: v3.21.2
hooks:
- id: pyupgrade
args: [--py39-plus]
args: [--py310-plus]
- repo: https://github.com/asottile/blacken-docs
rev: 1.20.0
hooks:
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -33,7 +32,7 @@ classifiers = [
]
description = "plugin and hook calling mechanisms for python"
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.9"
requires-python = ">=3.10"

dynamic = ["version"]
[dependency-groups]
Expand Down
13 changes: 8 additions & 5 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections.abc import Sequence
from typing import cast
from typing import NoReturn
from typing import TypeAlias
import warnings

from ._hooks import HookImpl
Expand All @@ -19,7 +20,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 = Generator[None, object, object]
Teardown: TypeAlias = Generator[None, object, object]


def run_old_style_hookwrapper(
Expand Down Expand Up @@ -66,10 +67,12 @@ def _raise_wrapfail(
def _warn_teardown_exception(
hook_name: str, hook_impl: HookImpl, e: BaseException
) -> None:
msg = "A plugin raised an exception during an old-style hookwrapper teardown.\n"
msg += f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
msg += f"{type(e).__name__}: {e}\n"
msg += "For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
msg = (
f"A plugin raised an exception during an old-style hookwrapper teardown.\n"
f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
f"{type(e).__name__}: {e}\n"
f"For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
)
warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=6)


Expand Down
20 changes: 11 additions & 9 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Mapping
from collections.abc import Sequence
Expand All @@ -12,29 +13,28 @@
import sys
from types import ModuleType
from typing import Any
from typing import Callable
from typing import Final
from typing import final
from typing import Optional
from typing import overload
from typing import TYPE_CHECKING
from typing import TypeAlias
from typing import TypedDict
from typing import TypeVar
from typing import Union
import warnings

from ._result import Result


_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., object])
_Namespace = Union[ModuleType, type]
_Plugin = object
_HookExec = Callable[

_Namespace: TypeAlias = ModuleType | type
_Plugin: TypeAlias = object
_HookExec: TypeAlias = Callable[
[str, Sequence["HookImpl"], Mapping[str, object], bool],
Union[object, list[object]],
object | list[object],
]
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
_HookImplFunction: TypeAlias = Callable[..., _T | Generator[None, Result[_T], None]]


class HookspecOpts(TypedDict):
Expand Down Expand Up @@ -374,7 +374,9 @@ def __getattr__(self, name: str) -> HookCaller: ...
_HookRelay = HookRelay


_CallHistory = list[tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
_CallHistory: TypeAlias = list[
tuple[Mapping[str, object], Callable[[Any], None] | None]
]


class HookCaller:
Expand Down
9 changes: 6 additions & 3 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import annotations

from collections.abc import Callable
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 TYPE_CHECKING
from typing import TypeAlias
import warnings

from . import _tracing
Expand All @@ -32,8 +33,10 @@
import importlib.metadata


_BeforeTrace = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
_AfterTrace = Callable[[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]
_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
_AfterTrace: TypeAlias = Callable[
[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None
]


def _warn_for_function(warning: Warning, function: Callable[..., object]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/pluggy/_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

from __future__ import annotations

from collections.abc import Callable
from types import TracebackType
from typing import Callable
from typing import cast
from typing import final
from typing import Generic
from typing import Optional
from typing import TypeAlias
from typing import TypeVar


_ExcInfo = tuple[type[BaseException], BaseException, Optional[TracebackType]]
_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None]
ResultType = TypeVar("ResultType")


Expand Down
10 changes: 3 additions & 7 deletions src/pluggy/_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

from __future__ import annotations

from collections.abc import Callable
from collections.abc import Sequence
from typing import Any
from typing import Callable


_Writer = Callable[[str], object]
Expand All @@ -32,7 +32,7 @@ def _format_message(self, tags: Sequence[str], args: Sequence[object]) -> str:
content = " ".join(map(str, args))
indent = " " * self.indent

lines = ["{}{} [{}]\n".format(indent, content, ":".join(tags))]
lines = [f"{indent}{content} [{':'.join(tags)}]\n"]

for name, value in extra.items():
lines.append(f"{indent} {name}: {value}\n")
Expand All @@ -42,11 +42,7 @@ def _format_message(self, tags: Sequence[str], args: Sequence[object]) -> str:
def _processmessage(self, tags: tuple[str, ...], args: tuple[object, ...]) -> None:
if self._writer is not None and args:
self._writer(self._format_message(tags, args))
try:
processor = self._tags2proc[tags]
except KeyError:
pass
else:
if processor := self._tags2proc.get(tags):
processor(tags, args)

def setwriter(self, writer: _Writer | None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion testing/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from functools import wraps
from typing import Any
from typing import Callable
from typing import cast
from typing import TypeVar

Expand Down
2 changes: 1 addition & 1 deletion testing/test_hookcaller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Sequence
from typing import Callable
from typing import TypeVar

import pytest
Expand Down
5 changes: 2 additions & 3 deletions testing/test_multicall.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections.abc import Callable
from collections.abc import Mapping
from collections.abc import Sequence
from typing import Callable
from typing import Union

import pytest

Expand All @@ -20,7 +19,7 @@ def MC(
methods: Sequence[Callable[..., object]],
kwargs: Mapping[str, object],
firstresult: bool = False,
) -> Union[object, list[object]]:
) -> object | list[object]:
caller = _multicall
hookfuncs = []
for method in methods:
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=docs,py{39,310,311,312,313,314,py3},py{39}-pytestmain
envlist=docs,py{310,311,312,313,314,py3},py{310}-pytestmain

[testenv]
commands=
Expand Down Expand Up @@ -40,7 +40,7 @@ filterwarnings =

[flake8]
max-line-length=99
min-python-version = 3.9
min-python-version = 3.10

[testenv:release]
description = do a release, required posarg of the version number
Expand Down
Loading