Skip to content

Commit

Permalink
feat: ParamSpec (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Nov 17, 2022
1 parent b479f4d commit 2be6122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 9 additions & 13 deletions eth_retry/eth_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@
MAX_RETRIES = int(os.environ.get("MAX_RETRIES", 10))

# Types
T = TypeVar("T")
if sys.version_info >= (3, 10):
from typing import ParamSpec
P = ParamSpec("P")
Function = Callable[P ,T]
CoroutineFunction = Function[Awaitable[T]]
Decoratee = Union[Function[P, T], CoroutineFunction[P, T]]
else:
Function = Callable[..., T]
CoroutineFunction = Function[Awaitable[T]]
Decoratee = Union[Function[T], CoroutineFunction[T]]
from typing_extensions import ParamSpec

T = TypeVar("T")
P = ParamSpec("P")
Function = Callable[P ,T]
CoroutineFunction = Function[P, Awaitable[T]]
Decoratee = Union[Function[P, T], CoroutineFunction[P, T]]

@overload
def auto_retry(func: CoroutineFunction[T]) -> CoroutineFunction[T]:...
def auto_retry(func: CoroutineFunction[P, T]) -> CoroutineFunction[P, T]:...

@overload
def auto_retry(func: Function[T]) -> Function[T]:...

def auto_retry(func: Decoratee[T]): # type: ignore
def auto_retry(func: Function[P, T]) -> Function[P, T]:
'''
Decorator that will retry the function on:
- ConnectionError
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
author_email='bobthebuidlerdefi@gmail.com',
url='https://github.com/BobTheBuidler/eth_retry',
license='MIT',
install_requires=[
'typing_extensions>=4.0.1',
],
setup_requires=[
'setuptools_scm',
],
Expand Down

0 comments on commit 2be6122

Please sign in to comment.