Skip to content

Commit 7a1d0ef

Browse files
committed
remove 2 uses of Any as sentinel value type
1 parent ddcb062 commit 7a1d0ef

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed

src/async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = "Michael Hall"
1010
__license__ = "Apache-2.0"
1111
__copyright__ = "Copyright 2020-Present Michael Hall"
12-
__version__ = "2025.04.6b"
12+
__version__ = "2025.04.9b"
1313

1414
import os
1515
import sys

src/async_utils/priority_sem.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ def priority_context(priority: int, /) -> Generator[None, None, None]:
8080
_priority.reset(token)
8181

8282

83-
_default: t.Any = object()
84-
85-
8683
class PrioritySemaphore:
8784
"""A Semaphore with priority-based aquisition ordering.
8885
@@ -154,9 +151,7 @@ async def __aenter__(self) -> None:
154151
async def __aexit__(self, *dont_care: object) -> None:
155152
self.__release()
156153

157-
async def __acquire(self, priority: int = _default) -> bool:
158-
if priority is _default:
159-
priority = _priority.get()
154+
async def __acquire(self, priority: int, /) -> bool:
160155
if not self.__locked():
161156
self._value -= 1
162157
return True

src/async_utils/scheduler.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
__all__ = ("CancellationToken", "Scheduler")
2424

25-
MISSING: t.Any = object()
26-
2725

2826
class CancellationToken:
2927
"""An object to use for cancelation of a task.
@@ -72,34 +70,17 @@ def __init_subclass__(cls) -> t.Never:
7270

7371
__final__ = True
7472

75-
__tasks: dict[CancellationToken, _Task[T]]
76-
__tqueue: asyncio.PriorityQueue[_Task[T]]
77-
__closed: bool
78-
__l: asyncio.Lock
79-
__granularity: float
80-
8173
__slots__ = ("__closed", "__granularity", "__l", "__tasks", "__tqueue")
8274

8375
def __init__(self, granularity: float, /) -> None:
84-
self.__granularity = granularity
85-
self.__closed = MISSING
86-
self.__tasks = MISSING
87-
self.__tqueue = MISSING
88-
self.__l = MISSING
89-
90-
async def __aenter__(self) -> t.Self:
91-
self.__closed = False
92-
asyncio.get_running_loop()
93-
94-
# lock is only needeed on modifying or removing tasks
95-
# insertion is not guarded and only racy in the order of emitted events
96-
# when inserting a task that is scheduled in the past
97-
# or within 1 full iteration of pending tasks on the event loop
98-
# (generally, ms range (subsecond), depending on application)
76+
self.__granularity: float = granularity
77+
self.__closed: bool = False
78+
self.__tasks: dict[CancellationToken, _Task[T]] = {}
79+
# PYUPGRADE: check: 3.15; relies on asyncio.Lock & Queues not eagerly binding to an event loop.
9980
self.__l = asyncio.Lock()
100-
self.__tasks = {}
101-
self.__tqueue = asyncio.PriorityQueue()
81+
self.__tqueue: asyncio.PriorityQueue[_Task[T]] = asyncio.PriorityQueue()
10282

83+
async def __aenter__(self) -> t.Self:
10384
return self
10485

10586
async def __aexit__(self, *_dont_care: object) -> None:

0 commit comments

Comments
 (0)