Skip to content

Commit

Permalink
add 'wrapped' type hint information
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil committed Dec 10, 2023
1 parent 23bbdd0 commit 3b420b3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tools/generate-tests
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ class Function:
''' ... '''
return 'return_value'"""

def type(self):
return f"Callable[..., {self.signature.return_type}]"
def type_hint(self, force_coro=False):
if self.signature.params_style == "param":
params = f"[{", ".join(self.signature.params_type for _ in range(self.signature.params_format.count(":")))}]"
elif self.signature.params_style == "kwargs":
params = f"[KwArg({self.signature.params_type})]"
else:
params = f"[VarArg({self.signature.params_type})]"
if self.coroutine or force_coro:
rtype = f"Awaitable[{self.signature.return_type}]"
else:
rtype = f"{self.signature.return_type}"
return f"Callable[{params}, {rtype}]"

@property
def test_name(self):
Expand Down Expand Up @@ -137,9 +147,10 @@ class Decoration:
return f"""@{self.build}
{self.function}"""
else:
type_hint = self.function.type_hint(self.decorator_name == "aioretry")
return f"""{self.function}
{self.decoration} = {self.build}({self.function.name})"""
{self.decoration}: {type_hint} = {self.build}({self.function.name})"""


def decorations(input_data) -> str:
Expand Down Expand Up @@ -185,7 +196,8 @@ reveal_type(func)
import asyncio
from typing import Any
from collections.abc import Callable, Awaitable
from mypy_extensions import VarArg, KwArg
from kaioretry import retry, aioretry, Retry, Context
Expand Down

0 comments on commit 3b420b3

Please sign in to comment.