Skip to content

Commit bfccbf1

Browse files
committed
feat: support py314
1 parent 000022d commit bfccbf1

File tree

6 files changed

+74
-39
lines changed

6 files changed

+74
-39
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ default_install_hook_types: [commit-msg, pre-commit, pre-push]
77
repos:
88

99
- repo: https://github.com/qoomon/git-conventional-commits
10-
rev: 'v2.6.7'
10+
rev: 'v2.7.2'
1111
hooks:
1212
- id: conventional-commits
1313
args: ["-c", ".git-commits.yaml"]
1414
stages: ["commit-msg"]
1515

1616
- repo: https://github.com/pre-commit/pre-commit-hooks
17-
rev: v4.6.0
17+
rev: v6.0.0
1818
hooks:
1919
- id: check-case-conflict
2020
stages: ["pre-commit"]
@@ -41,7 +41,7 @@ repos:
4141
stages: ["pre-commit"]
4242

4343
- repo: https://github.com/psf/black
44-
rev: 24.4.2
44+
rev: 25.9.0
4545
hooks:
4646
- id: black
4747
stages: ["pre-commit"]

asgi_tools/_compat.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Awaitable,
1515
Callable,
1616
Coroutine,
17-
Union,
1817
cast,
1918
)
2019

@@ -81,10 +80,10 @@ def aio_sleep(seconds: float = 0) -> Awaitable:
8180
"""Return sleep coroutine."""
8281

8382
if trio_installed and current_async_library() == "trio":
84-
return trio_sleep(seconds) # noqa: ASYNC105
83+
return trio_sleep(seconds) # noqa: ASYNC105 # type: ignore[]
8584

8685
if curio_installed and current_async_library() == "curio":
87-
return curio_sleep(seconds)
86+
return curio_sleep(seconds) # type: ignore[]
8887

8988
return sleep(seconds)
9089

@@ -93,12 +92,12 @@ def aio_sleep(seconds: float = 0) -> Awaitable:
9392
async def aio_spawn(fn: Callable[..., Awaitable], *args, **kwargs):
9493
"""Spawn a given coroutine."""
9594
if trio_installed and current_async_library() == "trio":
96-
async with open_nursery() as tasks:
95+
async with open_nursery() as tasks: # type: ignore[]
9796
tasks.start_soon(fn, *args, **kwargs)
9897
yield tasks
9998

10099
elif curio_installed and current_async_library() == "curio":
101-
task = await curio_spawn(fn, *args, **kwargs)
100+
task = await curio_spawn(fn, *args, **kwargs) # type: ignore[]
102101
yield task
103102
await task.join() # type: ignore [union-attr]
104103

@@ -118,18 +117,18 @@ async def aio_timeout(timeout: float): # noqa: ASYNC109
118117

119118
if trio_installed and current_async_library() == "trio":
120119
try:
121-
with trio_fail_after(timeout):
120+
with trio_fail_after(timeout): # type: ignore[]
122121
yield
123122

124-
except TooSlowError:
123+
except TooSlowError: # type: ignore[]
125124
raise TimeoutError(f"{timeout}s.") from None
126125

127126
elif curio_installed and current_async_library() == "curio":
128127
try:
129-
async with curio_fail_after(timeout):
128+
async with curio_fail_after(timeout): # type: ignore[]
130129
yield
131130

132-
except TaskTimeout:
131+
except TaskTimeout: # type: ignore[]
133132
raise TimeoutError(f"{timeout}s.") from None
134133

135134
else:
@@ -148,7 +147,7 @@ async def aio_wait(*aws: Awaitable, strategy: str = ALL_COMPLETED) -> Any:
148147
if trio_installed and current_async_library() == "trio":
149148
send_channel, receive_channel = open_memory_channel(0) # type: ignore[var-annotated]
150149

151-
async with open_nursery() as n:
150+
async with open_nursery() as n: # type: ignore[]
152151
for aw in aws:
153152
n.start_soon(trio_jockey, aw, send_channel)
154153

@@ -179,7 +178,7 @@ async def aio_wait(*aws: Awaitable, strategy: str = ALL_COMPLETED) -> Any:
179178
return [t.result() for t in done] # type: ignore[attr-defined]
180179

181180

182-
async def aio_cancel(task: Union[asyncio.Task, Any]):
181+
async def aio_cancel(task):
183182
"""Cancel asyncio task / trio nursery."""
184183
if isinstance(task, asyncio.Task):
185184
return task.cancel()
@@ -193,7 +192,7 @@ async def aio_cancel(task: Union[asyncio.Task, Any]):
193192

194193

195194
async def aio_stream_file(
196-
filepath: Union[str, Path], chunk_size: int = 32 * 1024
195+
filepath: Path | str, chunk_size: int = 32 * 1024
197196
) -> AsyncGenerator[bytes, None]:
198197
if trio_installed and current_async_library() == "trio":
199198
async with await trio_open_file(filepath, "rb") as fp:
@@ -238,7 +237,7 @@ def json_dumps(content) -> bytes:
238237
).encode("utf-8")
239238

240239

241-
def json_loads(obj: Union[bytes, str]) -> TJSON:
240+
def json_loads(obj: bytes | str) -> TJSON:
242241
"""Emulate orjson."""
243242
if isinstance(obj, bytes):
244243
obj = obj.decode("utf-8")

asgi_tools/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Mapping,
1010
MutableMapping,
1111
TypeVar,
12-
Union,
1312
)
1413

1514
if TYPE_CHECKING:
@@ -22,7 +21,7 @@
2221
TASGIHeaders = list[tuple[bytes, bytes]]
2322
TASGIApp = Callable[[TASGIScope, TASGIReceive, TASGISend], Awaitable[Any]]
2423

25-
TJSON = Union[None, bool, int, float, str, list["TJSON"], Mapping[str, "TJSON"]]
24+
TJSON = None | bool | int | float | str | list["TJSON"] | Mapping[str, "TJSON"]
2625
TExceptionHandler = Callable[["Request", BaseException], Coroutine[None, None, Any]]
2726

2827
TV = TypeVar("TV")

poetry.lock

Lines changed: 53 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "asgi-tools"
66
version = "1.3.3"
77
description = "ASGI Toolkit to build web applications"
88
readme = "README.rst"
9-
requires-python = ">=3.10"
9+
requires-python = ">=3.10,<4"
1010
license = { "text" = "MIT License" }
1111
authors = [{ name = "Kirill Klenov", email = "horneds@gmail.com" }]
1212
keywords = ["asgi", "asgi-tools", "request", "response", "asyncio", "trio"]
@@ -44,7 +44,7 @@ documentation = "https://klen.github.io/asgi-tools"
4444
tests = [
4545
"aiofile",
4646
"pytest",
47-
"pytest-aio[curio,trio] >= 1.3.3",
47+
"pytest-aio[curio,trio] >= 2",
4848
"pytest-benchmark",
4949
"PyYAML",
5050
"ruff",

tests/conftest.py

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

33
import pytest
4+
import uvloop
45

56

67
@pytest.fixture(
78
params=[
8-
pytest.param(("asyncio", {"use_uvloop": False}), id="asyncio"),
9-
pytest.param(("asyncio", {"use_uvloop": True}), id="asyncio+uvloop"),
9+
pytest.param(("asyncio", {"loop_factory": None}), id="asyncio"),
10+
pytest.param(("asyncio", {"loop_factory": uvloop.new_event_loop}), id="asyncio+uvloop"),
1011
"trio",
1112
"curio",
1213
],

0 commit comments

Comments
 (0)