Skip to content

Commit dbe2131

Browse files
Merge pull request #616 from RonnyPfannschmidt/refactor/require-python310
Require Python 3.10+ and modernize type annotations
2 parents 0c501ac + 009bdc3 commit dbe2131

File tree

13 files changed

+49
-163
lines changed

13 files changed

+49
-163
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ jobs:
3030
fail-fast: false
3131
matrix:
3232
name: [
33-
"windows-py39",
33+
"windows-py310",
3434
"windows-py314",
3535
"windows-pypy3",
3636

3737
"ubuntu-py310-pytestmain",
38-
"ubuntu-py39",
3938
"ubuntu-py310",
4039
"ubuntu-py311",
4140
"ubuntu-py312",
@@ -46,10 +45,10 @@ jobs:
4645
]
4746

4847
include:
49-
- name: "windows-py39"
50-
python: "3.9"
48+
- name: "windows-py310"
49+
python: "3.10"
5150
os: windows-latest
52-
tox_env: "py39"
51+
tox_env: "py310"
5352
- name: "windows-py313"
5453
python: "3.13"
5554
os: windows-latest
@@ -59,23 +58,19 @@ jobs:
5958
os: windows-latest
6059
tox_env: "py314"
6160
- name: "windows-pypy3"
62-
python: "pypy3.9"
61+
python: "pypy3.10"
6362
os: windows-latest
6463
tox_env: "pypy3"
6564
- name: "ubuntu-py310-pytestmain"
6665
python: "3.10"
6766
os: ubuntu-latest
6867
tox_env: "py310-pytestmain"
6968
use_coverage: true
70-
- name: "ubuntu-py39"
71-
python: "3.9"
72-
os: ubuntu-latest
73-
tox_env: "py39"
74-
use_coverage: true
7569
- name: "ubuntu-py310"
7670
python: "3.10"
7771
os: ubuntu-latest
7872
tox_env: "py310"
73+
use_coverage: true
7974
- name: "ubuntu-py311"
8075
python: "3.11"
8176
os: ubuntu-latest
@@ -97,12 +92,12 @@ jobs:
9792
tox_env: "py314"
9893
use_coverage: true
9994
- name: "ubuntu-pypy3"
100-
python: "pypy3.9"
95+
python: "pypy3.10"
10196
os: ubuntu-latest
10297
tox_env: "pypy3"
10398
use_coverage: true
10499
- name: "ubuntu-benchmark"
105-
python: "3.9"
100+
python: "3.10"
106101
os: ubuntu-latest
107102
tox_env: "benchmark"
108103

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
rev: v3.21.2
2929
hooks:
3030
- id: pyupgrade
31-
args: [--py39-plus]
31+
args: [--py310-plus]
3232
- repo: https://github.com/asottile/blacken-docs
3333
rev: 1.20.0
3434
hooks:

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ classifiers = [
2424
"Programming Language :: Python :: Implementation :: PyPy",
2525
"Programming Language :: Python :: 3",
2626
"Programming Language :: Python :: 3 :: Only",
27-
"Programming Language :: Python :: 3.9",
2827
"Programming Language :: Python :: 3.10",
2928
"Programming Language :: Python :: 3.11",
3029
"Programming Language :: Python :: 3.12",
@@ -33,7 +32,7 @@ classifiers = [
3332
]
3433
description = "plugin and hook calling mechanisms for python"
3534
readme = {file = "README.rst", content-type = "text/x-rst"}
36-
requires-python = ">=3.9"
35+
requires-python = ">=3.10"
3736

3837
dynamic = ["version"]
3938
[dependency-groups]

src/pluggy/_callers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections.abc import Sequence
1010
from typing import cast
1111
from typing import NoReturn
12+
from typing import TypeAlias
1213
import warnings
1314

1415
from ._hooks import HookImpl
@@ -19,7 +20,7 @@
1920

2021
# Need to distinguish between old- and new-style hook wrappers.
2122
# Wrapping with a tuple is the fastest type-safe way I found to do it.
22-
Teardown = Generator[None, object, object]
23+
Teardown: TypeAlias = Generator[None, object, object]
2324

2425

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

7578

src/pluggy/_hooks.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
from collections.abc import Callable
78
from collections.abc import Generator
89
from collections.abc import Mapping
910
from collections.abc import Sequence
@@ -12,29 +13,28 @@
1213
import sys
1314
from types import ModuleType
1415
from typing import Any
15-
from typing import Callable
1616
from typing import Final
1717
from typing import final
18-
from typing import Optional
1918
from typing import overload
2019
from typing import TYPE_CHECKING
20+
from typing import TypeAlias
2121
from typing import TypedDict
2222
from typing import TypeVar
23-
from typing import Union
2423
import warnings
2524

2625
from ._result import Result
2726

2827

2928
_T = TypeVar("_T")
3029
_F = TypeVar("_F", bound=Callable[..., object])
31-
_Namespace = Union[ModuleType, type]
32-
_Plugin = object
33-
_HookExec = Callable[
30+
31+
_Namespace: TypeAlias = ModuleType | type
32+
_Plugin: TypeAlias = object
33+
_HookExec: TypeAlias = Callable[
3434
[str, Sequence["HookImpl"], Mapping[str, object], bool],
35-
Union[object, list[object]],
35+
object | list[object],
3636
]
37-
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
37+
_HookImplFunction: TypeAlias = Callable[..., _T | Generator[None, Result[_T], None]]
3838

3939

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

376376

377-
_CallHistory = list[tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
377+
_CallHistory: TypeAlias = list[
378+
tuple[Mapping[str, object], Callable[[Any], None] | None]
379+
]
378380

379381

380382
class HookCaller:

src/pluggy/_manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from __future__ import annotations
22

3+
from collections.abc import Callable
34
from collections.abc import Iterable
45
from collections.abc import Mapping
56
from collections.abc import Sequence
67
import inspect
78
import types
89
from typing import Any
9-
from typing import Callable
1010
from typing import cast
1111
from typing import Final
1212
from typing import TYPE_CHECKING
13+
from typing import TypeAlias
1314
import warnings
1415

1516
from . import _tracing
@@ -32,8 +33,10 @@
3233
import importlib.metadata
3334

3435

35-
_BeforeTrace = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
36-
_AfterTrace = Callable[[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None]
36+
_BeforeTrace: TypeAlias = Callable[[str, Sequence[HookImpl], Mapping[str, Any]], None]
37+
_AfterTrace: TypeAlias = Callable[
38+
[Result[Any], str, Sequence[HookImpl], Mapping[str, Any]], None
39+
]
3740

3841

3942
def _warn_for_function(warning: Warning, function: Callable[..., object]) -> None:

src/pluggy/_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
from __future__ import annotations
66

7+
from collections.abc import Callable
78
from types import TracebackType
8-
from typing import Callable
99
from typing import cast
1010
from typing import final
1111
from typing import Generic
12-
from typing import Optional
12+
from typing import TypeAlias
1313
from typing import TypeVar
1414

1515

16-
_ExcInfo = tuple[type[BaseException], BaseException, Optional[TracebackType]]
16+
_ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None]
1717
ResultType = TypeVar("ResultType")
1818

1919

src/pluggy/_tracing.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
from __future__ import annotations
66

7+
from collections.abc import Callable
78
from collections.abc import Sequence
89
from typing import Any
9-
from typing import Callable
1010

1111

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

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

3737
for name, value in extra.items():
3838
lines.append(f"{indent} {name}: {value}\n")
@@ -42,11 +42,7 @@ def _format_message(self, tags: Sequence[str], args: Sequence[object]) -> str:
4242
def _processmessage(self, tags: tuple[str, ...], args: tuple[object, ...]) -> None:
4343
if self._writer is not None and args:
4444
self._writer(self._format_message(tags, args))
45-
try:
46-
processor = self._tags2proc[tags]
47-
except KeyError:
48-
pass
49-
else:
45+
if processor := self._tags2proc.get(tags):
5046
processor(tags, args)
5147

5248
def setwriter(self, writer: _Writer | None) -> None:

testing/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from collections.abc import Callable
12
from functools import wraps
23
from typing import Any
3-
from typing import Callable
44
from typing import cast
55
from typing import TypeVar
66

testing/test_hookcaller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
from collections.abc import Callable
12
from collections.abc import Generator
23
from collections.abc import Sequence
3-
from typing import Callable
44
from typing import TypeVar
55

66
import pytest

0 commit comments

Comments
 (0)