Skip to content

Commit dd132a2

Browse files
committed
We're already having to check more complex internals per version, let's use _tuplegetter
1 parent ac65c0d commit dd132a2

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

src/async_utils/priority_sem.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import contextvars
2020
import heapq
2121
import threading
22-
from collections.abc import Callable, Generator
22+
from collections.abc import Generator
2323
from contextlib import contextmanager
2424

2525
from . import _typings as t
26+
from ._faux_native import PriorityWaiter
2627

2728
__all__ = ["PrioritySemaphore", "priority_context"]
2829

@@ -31,41 +32,6 @@
3132
_priority: contextvars.ContextVar[int] = contextvars.ContextVar("_priority", default=0)
3233

3334

34-
class PriorityWaiter(tuple[int, float, asyncio.Future[None]]):
35-
__slots__ = ()
36-
37-
def __new__(cls, priority: int, ts: float, future: asyncio.Future[None]) -> t.Self:
38-
return super().__new__(cls, (priority, ts, future))
39-
40-
@property
41-
def priority(self) -> int:
42-
return self[0]
43-
44-
@property
45-
def ts(self) -> float:
46-
return self[1]
47-
48-
@property
49-
def future(self) -> asyncio.Future[None]:
50-
return self[2]
51-
52-
@property
53-
def cancelled(self) -> Callable[[], bool]:
54-
return self.future.cancelled
55-
56-
@property
57-
def done(self) -> Callable[[], bool]:
58-
return self.future.done
59-
60-
def __await__(self) -> Generator[t.Any, t.Any, None]:
61-
return self.future.__await__()
62-
63-
def __lt__(self, other: t.Any) -> bool:
64-
if not isinstance(other, PriorityWaiter):
65-
return NotImplemented
66-
return self[:2] < other[:2]
67-
68-
6935
@contextmanager
7036
def priority_context(priority: int, /) -> Generator[None, None, None]:
7137
"""Set the priority for all PrioritySemaphore use in this context.

0 commit comments

Comments
 (0)