File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 29
29
T = TypeVar ("T" )
30
30
31
31
32
+ class NoValue :
33
+ """Sentinel class for missing values."""
34
+
35
+
36
+ NO_VALUE = NoValue ()
37
+
38
+
32
39
class CapacityLimiter :
33
40
"""Limits the number of concurrent operations using a semaphore."""
34
41
@@ -240,11 +247,7 @@ def with_ensure_async_(
240
247
return obj
241
248
242
249
243
- class NoValue :
244
- """Sentinel class for missing values."""
245
-
246
-
247
- async def get_next (iterable : Any , default : Any = NoValue , * args : Any ) -> Any : # pragma: no cover
250
+ async def get_next (iterable : Any , default : Any = NO_VALUE , * args : Any ) -> Any : # pragma: no cover
248
251
"""Return the next item from an async iterator.
249
252
250
253
Args:
Original file line number Diff line number Diff line change @@ -320,6 +320,9 @@ async def test_get_next_with_default() -> None:
320
320
"""Test get_next with default value when iterator is exhausted."""
321
321
322
322
class EmptyAsyncIterator :
323
+ def __aiter__ (self ) -> "EmptyAsyncIterator" :
324
+ return self
325
+
323
326
async def __anext__ (self ) -> int :
324
327
raise StopAsyncIteration
325
328
@@ -334,17 +337,17 @@ async def test_get_next_no_default_behavior() -> None:
334
337
"""Test get_next behavior when iterator is exhausted without default."""
335
338
336
339
class EmptyAsyncIterator :
340
+ def __aiter__ (self ) -> "EmptyAsyncIterator" :
341
+ return self
342
+
337
343
async def __anext__ (self ) -> int :
338
344
raise StopAsyncIteration
339
345
340
346
iterator = EmptyAsyncIterator ()
341
347
342
- try :
343
- result = await get_next (iterator )
344
-
345
- assert isinstance (result , type (NoValue ))
346
- except StopAsyncIteration :
347
- pass
348
+ # Should raise StopAsyncIteration when no default is provided
349
+ with pytest .raises (StopAsyncIteration ):
350
+ await get_next (iterator )
348
351
349
352
350
353
def test_no_value_class () -> None :
You can’t perform that action at this time.
0 commit comments