chore: require python 3.12 and adopt PEP 695 type parameters
The telemetry write budget needs asyncio.timeout, whose uncancel accounting was only fixed after 3.11.1 — pinning the floor at 3.12 removes that hazard instead of working around it. Raising ruff's target-version turns on UP047, so gather_bounded, _anext_within and stream_with_liveness_timeouts move to def f[T](...) and the two module-level TypeVars go away. That syntax is a SyntaxError on 3.11, so it can only land together with the version bump.
This commit is contained in:
@@ -13,7 +13,7 @@ import hashlib
|
||||
import json
|
||||
import random
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Literal, TypeVar
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from polygateway.backends.memory.breaker import InMemoryGate
|
||||
from polygateway.backends.memory.cache import InMemoryCache
|
||||
@@ -63,8 +63,6 @@ if TYPE_CHECKING:
|
||||
SourceConfig,
|
||||
)
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
|
||||
def _guard_thinking(
|
||||
sources: list[SourceConfig],
|
||||
@@ -442,7 +440,7 @@ def _build_structured(
|
||||
return None, None
|
||||
|
||||
|
||||
async def gather_bounded(aws: Iterable[Awaitable[_T]], *, concurrency: int) -> list[_T]:
|
||||
async def gather_bounded[T](aws: Iterable[Awaitable[T]], *, concurrency: int) -> list[T]:
|
||||
"""有界并发 gather(D5 便利函数,替代 VT 手搓 semaphore+gather 样板)。
|
||||
|
||||
语义与 `asyncio.gather` 默认一致: 结果保序、首个异常上抛;仅增加并发上限。
|
||||
@@ -451,7 +449,7 @@ async def gather_bounded(aws: Iterable[Awaitable[_T]], *, concurrency: int) -> l
|
||||
raise ValueError("concurrency 必须 ≥ 1")
|
||||
sem = asyncio.Semaphore(concurrency)
|
||||
|
||||
async def _run(aw: Awaitable[_T]) -> _T:
|
||||
async def _run(aw: Awaitable[T]) -> T:
|
||||
async with sem:
|
||||
return await aw
|
||||
|
||||
|
||||
Reference in New Issue
Block a user