Skip to content

Commit ae461c9

Browse files
authored
Merge pull request #230 from aiokitchen/hotfix/threaded-instance-for-methods
Return Threaded instance for methods
2 parents 0d2e9ce + 0864628 commit ae461c9

File tree

10 files changed

+281
-62
lines changed

10 files changed

+281
-62
lines changed

aiomisc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from . import io, log
22
from ._context_vars import StrictContextVar
33
from .aggregate import aggregate, aggregate_async
4-
from .backoff import asyncbackoff, asyncretry, Backoff, BackoffExecution
4+
from .backoff import Backoff, BackoffExecution, asyncbackoff, asyncretry
55
from .circuit_breaker import CircuitBreaker, CircuitBroken, cutout
66
from .context import Context, get_context
77
from .counters import Statistic, get_statistics

aiomisc/backoff.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
2-
32
from functools import wraps
43
from typing import (
5-
Any, Callable, Coroutine, Optional, Tuple, Type, TypeVar, Union, Generic,
6-
ParamSpec
4+
Any, Callable, Coroutine, Generic, Optional, ParamSpec, Tuple, Type,
5+
TypeVar, Union,
76
)
87

98
from .counters import Statistic
@@ -46,7 +45,7 @@ def __init__(
4645
max_tries: Optional[int] = None,
4746
giveup: Optional[Callable[[Exception], bool]] = None,
4847
statistic_name: Optional[str] = None,
49-
statistic_class: Type[BackoffStatistic] = BackoffStatistic
48+
statistic_class: Type[BackoffStatistic] = BackoffStatistic,
5049
):
5150
if not pause:
5251
pause = 0
@@ -78,7 +77,7 @@ def __init__(
7877

7978
def prepare(
8079
self,
81-
func: Callable[P, Coroutine[Any, Any, T]]
80+
func: Callable[P, Coroutine[Any, Any, T]],
8281
) -> "BackoffExecution[P, T]":
8382
return BackoffExecution(
8483
function=func,
@@ -95,14 +94,14 @@ async def execute(
9594
self,
9695
func: Callable[P, Coroutine[Any, Any, T]],
9796
*args: P.args,
98-
**kwargs: P.kwargs
97+
**kwargs: P.kwargs,
9998
) -> T:
10099
execution = self.prepare(func)
101100
return await execution(*args, **kwargs)
102101

103102
def __call__(
104103
self,
105-
func: Callable[P, Coroutine[Any, Any, T]]
104+
func: Callable[P, Coroutine[Any, Any, T]],
106105
) -> Callable[P, Coroutine[Any, Any, T]]:
107106
if not asyncio.iscoroutinefunction(func):
108107
raise TypeError("Function must be a coroutine function")

aiomisc/compat.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import os
44
import socket
55
from typing import (
6-
Any, Iterator, Optional, final, TypeAlias, ParamSpec,
7-
Protocol
6+
Any, Iterator, Optional, ParamSpec, Protocol, TypeAlias, final,
87
)
98

109
from ._context_vars import EVENT_LOOP
1110

11+
1212
log = logging.getLogger(__name__)
1313

14+
1415
try:
1516
from time import time_ns
1617
except ImportError:
@@ -20,6 +21,12 @@ def time_ns() -> int:
2021
return int(time() * 1000000000)
2122

2223

24+
try:
25+
from typing import Concatenate
26+
except ImportError:
27+
from typing_extensions import Concatenate
28+
29+
2330
class EntrypointProtocol(Protocol):
2431
@property
2532
def name(self) -> str:
@@ -98,6 +105,7 @@ def sock_set_reuseport(sock: socket.socket, reuse_port: bool) -> None:
98105
get_current_loop = EVENT_LOOP.get
99106

100107
__all__ = (
108+
"Concatenate",
101109
"EntrypointProtocol",
102110
"EventLoopMixin",
103111
"ParamSpec",

aiomisc/iterator_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from time import time
99
from types import TracebackType
1010
from typing import (
11-
Any, AsyncIterator, Awaitable, Callable, Deque, Generator, NoReturn,
12-
Optional, Type, TypeVar, Union, Generic, ParamSpec,
11+
Any, AsyncIterator, Awaitable, Callable, Deque, Generator, Generic,
12+
NoReturn, Optional, ParamSpec, Type, TypeVar, Union,
1313
)
1414
from weakref import finalize
1515

0 commit comments

Comments
 (0)