small fixes to type annotations
All checks were successful
CI / build (push) Successful in 18s

This commit is contained in:
2024-11-01 09:21:01 +08:00
parent 40791a9c6e
commit e0e763170f
3 changed files with 13 additions and 9 deletions

View File

@@ -6,10 +6,12 @@ from .private import (
ExceptionHandlerOutcome,
tmpdir,
decorator_with_kwargs,
classproperty
classproperty,
AsyncQueueIterator
)
from .maybe import Maybe
from .notification import TopicManager, Subscriber
__all__ = [
'format_filesize',
'async_retry',
@@ -21,5 +23,6 @@ __all__ = [
'decorator_with_kwargs',
'classproperty',
'TopicManager',
'Subscriber'
'Subscriber',
'AsyncQueueIterator'
]

View File

@@ -53,6 +53,7 @@ class Maybe(Generic[T]):
def __or__(self, alt: Maybe[T]) -> Maybe[T]:
return self if self.is_present else alt
def or_else(self, alt: T) -> T:
return self.value if self.is_present else alt
@@ -65,7 +66,7 @@ class Maybe(Generic[T]):
else:
raise supplier()
def or_else_get(self, supplier: Callable[[], T]) -> Maybe[T]:
def or_else_get(self, supplier: Callable[[], Optional[T]]) -> Maybe[T]:
return self if self.is_present else Maybe.of_nullable(supplier())
def if_present(self, callback: Callable[[T], U]) -> None:

View File

@@ -6,7 +6,7 @@ from inspect import signature
from pathlib import Path
from tempfile import TemporaryDirectory
from time import sleep
from typing import Callable
from typing import Callable, AsyncIterator
def decorator_with_kwargs(decorator: Callable) -> Callable:
@@ -207,16 +207,16 @@ def classproperty(func):
return ClassPropertyDescriptor(func)
class AsyncQueueIterator:
_queue: Queue
class AsyncQueueIterator[T]:
_queue: Queue[T]
def __init__(self, queue: Queue):
def __init__(self, queue: Queue[T]):
self._queue = queue
def __aiter__(self):
def __aiter__(self) -> AsyncIterator[T]:
return self
async def __anext__(self):
async def __anext__(self) -> [T]:
item = await self._queue.get()
if item is None:
raise StopAsyncIteration