Skip to content

Commit

Permalink
fix _ContextIterator and Context usage of SleepRetVal
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil committed Nov 24, 2023
1 parent fc6a182 commit bd6fed0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kaioretry/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import logging
import uuid

from typing import cast, Awaitable, Any, TypeVar
from typing import cast, Awaitable, Any, TypeVar, Generic
from collections.abc import Callable, Generator, AsyncGenerator

from .types import NonNegative, Number, UpdateDelayFunc
Expand All @@ -103,7 +103,7 @@
SleepF = Callable[[Number], SleepRetVal]


class _ContextIterator:
class _ContextIterator(Generic[SleepRetVal]):
"""Single-usage helper class for Context objects."""

# pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -225,7 +225,7 @@ def __update_delay(self, delay: NonNegative) -> NonNegative:
return delay

def __make_iterator(
self, sleep: SleepF[Any]) -> Generator[SleepRetVal, None, None]:
self, sleep: SleepF[SleepRetVal]) -> Generator[SleepRetVal, None, None]:
return iter(_ContextIterator(
uuid.uuid4(), sleep, self.__tries, self.__delay,
self.__update_delay, self.__logger))
Expand All @@ -236,8 +236,7 @@ def __iter__(self) -> Generator[None, None, None]:

async def __aiter__(self) -> AsyncGenerator[None, None]:
yield
for sleep in cast(Generator[Awaitable[None], None, None],
self.__make_iterator(asyncio.sleep)):
for sleep in self.__make_iterator(asyncio.sleep):
await sleep
yield

Expand Down

0 comments on commit bd6fed0

Please sign in to comment.