Skip to content

Commit 86f2239

Browse files
authored
Merge pull request #29 from nolar/drop-python-3.10
Drop Python 3.10 support
2 parents a1086e7 + 75e2b37 commit 86f2239

10 files changed

Lines changed: 33 additions & 46 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
# Assumption: if free-threaded works in one version, it works in all versions.
28-
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t" ]
28+
python-version: [ "3.11", "3.12", "3.13", "3.14", "3.14t" ]
2929
name: Python ${{ matrix.python-version }}${{ matrix.install-extras && ', ' || '' }}${{ matrix.install-extras }}
3030
runs-on: ubuntu-26.04
3131
timeout-minutes: 5
@@ -61,7 +61,7 @@ jobs:
6161
strategy:
6262
fail-fast: false
6363
matrix:
64-
python-version: [ "pypy-3.10", "pypy-3.11", "pypy-3.12" ]
64+
python-version: [ "pypy-3.11", "pypy-3.12" ]
6565
name: Python ${{ matrix.python-version }}
6666
runs-on: ubuntu-26.04
6767
timeout-minutes: 5

‎.github/workflows/thorough.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
# Assumption: if free-threaded works in one version, it works in all versions.
30-
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14", "3.14t" ]
30+
python-version: [ "3.11", "3.12", "3.13", "3.14", "3.14t" ]
3131
name: Python ${{ matrix.python-version }}
3232
runs-on: ubuntu-26.04
3333
timeout-minutes: 5
@@ -61,7 +61,7 @@ jobs:
6161
strategy:
6262
fail-fast: false
6363
matrix:
64-
python-version: [ "pypy-3.10", "pypy-3.11", "pypy-3.12" ]
64+
python-version: [ "pypy-3.11", "pypy-3.12" ]
6565
name: Python ${{ matrix.python-version }}
6666
runs-on: ubuntu-26.04
6767
timeout-minutes: 5

‎.pre-commit-config.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ repos:
5858
- id: rst-inline-touching-normal
5959
- id: text-unicode-replacement-char
6060

61+
- repo: https://github.com/asottile/pyupgrade
62+
rev: v3.21.2
63+
hooks:
64+
- id: pyupgrade
65+
args: [--py311-plus, --keep-mock]
66+
6167
- repo: https://github.com/PyCQA/isort
6268
rev: 6.0.1
6369
hooks:

‎looptime/_internal/chronometers.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
from __future__ import annotations
22

33
import time
4-
from typing import Any, Callable, TypeVar
4+
from collections.abc import Callable
5+
from typing import Any, Self
56

67
from . import math
78

8-
_SelfT = TypeVar('_SelfT', bound="Chronometer")
9-
109

1110
class Chronometer(math.Numeric):
1211
"""
@@ -52,15 +51,15 @@ def __repr__(self) -> str:
5251
status = 'new' if self._ts is None else 'running' if self._te is None else 'finished'
5352
return f'<Chronometer: {self.seconds}s ({status})>'
5453

55-
def __enter__(self: _SelfT) -> _SelfT:
54+
def __enter__(self) -> Self:
5655
self._ts = self._clock()
5756
self._te = None
5857
return self
5958

6059
def __exit__(self, *args: Any) -> None:
6160
self._te = self._clock()
6261

63-
async def __aenter__(self: _SelfT) -> _SelfT:
62+
async def __aenter__(self) -> Self:
6463
return self.__enter__()
6564

6665
async def __aexit__(self, *args: Any) -> None:

‎looptime/_internal/enabler.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import functools
33
import inspect
44
import warnings
5-
from typing import Any, Callable, ContextManager, ParamSpec, TypeVar
5+
from collections.abc import Callable
6+
from typing import Any, ContextManager, ParamSpec, TypeVar
67

78
from . import loops
89

‎looptime/_internal/loops.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import time
77
import warnings
88
import weakref
9-
from typing import TYPE_CHECKING, Any, Callable, Iterator, MutableSet, TypeVar, cast, overload
9+
from collections.abc import Callable, Iterator, MutableSet
10+
from typing import TYPE_CHECKING, Any, TypeVar, cast, overload
1011

1112
_T = TypeVar('_T')
1213

‎looptime/_internal/patchers.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from . import loops
77

8-
_class_cache: dict[Type[asyncio.BaseEventLoop], Type[loops.LoopTimeEventLoop]] = {}
8+
_class_cache: dict[type[asyncio.BaseEventLoop], type[loops.LoopTimeEventLoop]] = {}
99

1010

1111
def reset_caches() -> None:
@@ -19,10 +19,10 @@ def reset_caches() -> None:
1919

2020

2121
def make_event_loop_class(
22-
cls: Type[asyncio.BaseEventLoop],
22+
cls: type[asyncio.BaseEventLoop],
2323
*,
2424
prefix: str = 'Looptime',
25-
) -> Type[loops.LoopTimeEventLoop]:
25+
) -> type[loops.LoopTimeEventLoop]:
2626
"""
2727
Create a new looptime-enabled event loop class from the original class.
2828

‎looptime/_internal/plugin.py‎

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,40 +162,24 @@ def pytest_fixture_setup(fixturedef: pytest.FixtureDef[Any], request: pytest.Fix
162162
result = yield
163163

164164
# Only do the magic if in the area of our interest & only for fixtures making the event loops.
165-
# TODO: rewrite to simpler `if` & match-case when Python 3.10 is dropped (≈October 2026).
166165
should_patch = _should_patch(fixturedef, request)
167-
is_loop = isinstance(result, asyncio.BaseEventLoop)
168-
is_runner = False if sys.version_info < (3, 11) else isinstance(result, asyncio.Runner)
169-
is_bp_runner = False if sys.version_info < (3, 11) else isinstance(result, asyncio.Runner)
170-
171-
# We avoid extra dependencies, but pytest-asyncio>=1.1.0 uses it, and we need to detect it.
172-
# TODO: remove when Python 3.10 is dropped (≈October 2026).
173-
try:
174-
from backports.asyncio.runner import Runner as bp_Runner
175-
except ImportError:
176-
is_bp_runner = False
177-
else:
178-
is_bp_runner = isinstance(result, bp_Runner)
179166

180167
# Patch the event loop at creation — even if unused and not enabled. We cannot patch later
181168
# in the middle of the run: e.g. for a session-scoped loop used in a few tests out of many.
182169
# NB: For the lowest "function" scope, we still cannot decide which options to use, since
183170
# we do not know yet if it will be the running loop or not — so we cannot optimize here
184171
# in order to patch-and-configure only once; we must patch here & configure+activate later.
185-
if should_patch and (is_loop or is_runner or is_bp_runner):
186-
if isinstance(result, asyncio.BaseEventLoop):
187-
patchers.patch_event_loop(result, _enabled=False)
188-
elif sys.version_info >= (3, 11) and isinstance(result, asyncio.Runner):
189-
# Available only in python>=3.11, but mandatory for python>=3.14.
190-
# The runner of pytest-asyncio is already entered, which means the loop is created.
191-
# Even if not created, we cannot postpone the loop creation, so we create it here.
192-
loop = result.get_loop()
193-
if isinstance(loop, asyncio.BaseEventLoop):
194-
patchers.patch_event_loop(loop, _enabled=False)
195-
elif is_bp_runner: # TODO: drop this branch with Python 3.10
196-
loop = result.get_loop()
197-
if isinstance(loop, asyncio.BaseEventLoop):
198-
patchers.patch_event_loop(loop, _enabled=False)
172+
if should_patch:
173+
match result:
174+
case asyncio.BaseEventLoop():
175+
patchers.patch_event_loop(result, _enabled=False)
176+
case asyncio.Runner():
177+
# Available only in python>=3.11, but mandatory for python>=3.14.
178+
# The runner of pytest-asyncio is already entered, which means the loop is created.
179+
# Even if not created, we cannot postpone the loop creation, so we create it here.
180+
loop = result.get_loop()
181+
if isinstance(loop, asyncio.BaseEventLoop):
182+
patchers.patch_event_loop(loop, _enabled=False)
199183

200184
return result
201185

‎pyproject.toml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ classifiers = [
1818
"Framework :: aiohttp",
1919
"Programming Language :: Python",
2020
"Programming Language :: Python :: 3",
21-
"Programming Language :: Python :: 3.10",
2221
"Programming Language :: Python :: 3.11",
2322
"Programming Language :: Python :: 3.12",
2423
"Programming Language :: Python :: 3.13",
@@ -30,7 +29,7 @@ classifiers = [
3029
"Topic :: Software Development :: Libraries",
3130
"Typing :: Typed",
3231
]
33-
requires-python = ">=3.10"
32+
requires-python = ">=3.11"
3433
dependencies = [
3534
]
3635
dynamic = ["version"] # taken from git tags

‎tests/test_enabler.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ async def fn(a: int) -> tuple[int, bool]:
5151
assert enabled
5252

5353

54-
@pytest.mark.skipif(sys.version_info < (3, 11), reason="Runners require Python>=3.11")
5554
def test_enabler_with_explicit_loop():
5655
with asyncio.Runner() as runner:
5756
runner_loop = runner.get_loop()
@@ -61,7 +60,6 @@ def test_enabler_with_explicit_loop():
6160
assert enabled
6261

6362

64-
@pytest.mark.skipif(sys.version_info < (3, 11), reason="Runners require Python>=3.11")
6563
def test_strict_mode_error():
6664
with asyncio.Runner() as runner:
6765
runner_loop = runner.get_loop() # unpatched!
@@ -70,7 +68,6 @@ def test_strict_mode_error():
7068
pass
7169

7270

73-
@pytest.mark.skipif(sys.version_info < (3, 11), reason="Runners require Python>=3.11")
7471
def test_nonstrict_mode_warning():
7572
with asyncio.Runner() as runner:
7673
runner_loop = runner.get_loop() # unpatched!

0 commit comments

Comments
 (0)