pre-commit refresh

This commit is contained in:
Stéphane Bidoul 2025-09-14 11:46:57 +02:00
parent 7e160510a0
commit fc4dc2a8e7
2 changed files with 6 additions and 11 deletions

View file

@ -2,14 +2,14 @@ default_language_version:
python: python3 python: python3
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 rev: v6.0.0
hooks: hooks:
- id: check-toml - id: check-toml
- id: check-yaml - id: check-yaml
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.9 rev: v0.13.0
hooks: hooks:
- id: ruff - id: ruff-check
- id: ruff-format - id: ruff-format

View file

@ -4,7 +4,7 @@ import re
from collections.abc import AsyncGenerator, Awaitable, Callable, Generator, Iterator from collections.abc import AsyncGenerator, Awaitable, Callable, Generator, Iterator
from concurrent.futures.thread import ThreadPoolExecutor from concurrent.futures.thread import ThreadPoolExecutor
from functools import wraps from functools import wraps
from typing import Any, ParamSpec, TypeVar from typing import Any
_pool = ThreadPoolExecutor(max_workers=20, thread_name_prefix="sync_to_async") _pool = ThreadPoolExecutor(max_workers=20, thread_name_prefix="sync_to_async")
@ -13,12 +13,7 @@ def slugify(s: str | int) -> str:
return re.sub(r"[^a-z0-9]", "-", str(s).lower()) return re.sub(r"[^a-z0-9]", "-", str(s).lower())
P = ParamSpec("P") def sync_to_async[**P, R](func: Callable[P, R]) -> Callable[P, Awaitable[R]]:
R = TypeVar("R")
T = TypeVar("T")
def sync_to_async(func: Callable[P, R]) -> Callable[P, Awaitable[R]]:
@wraps(func) @wraps(func)
async def inner(*args: Any, **kwargs: Any) -> R: async def inner(*args: Any, **kwargs: Any) -> R:
f = functools.partial(func, *args, **kwargs) f = functools.partial(func, *args, **kwargs)
@ -27,7 +22,7 @@ def sync_to_async(func: Callable[P, R]) -> Callable[P, Awaitable[R]]:
return inner return inner
def sync_to_async_iterator( def sync_to_async_iterator[**P, R](
iterator_func: Callable[P, Generator[R]], iterator_func: Callable[P, Generator[R]],
) -> Callable[P, AsyncGenerator[R]]: ) -> Callable[P, AsyncGenerator[R]]:
@sync_to_async @sync_to_async