Skip to content

Commit

Permalink
Improve decorator typing
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Dec 9, 2023
1 parent 47cdaea commit b1fec52
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions miru/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def url(self) -> t.Optional[str]:
return self._url

@url.setter
def url(self, value: str) -> None:
def url(self, value: t.Optional[str]) -> None:
if value and not isinstance(value, str):
raise TypeError("Expected type 'str' for property 'url'.")

Expand Down Expand Up @@ -174,7 +174,7 @@ def button(
emoji: t.Optional[t.Union[str, hikari.Emoji]] = None,
row: t.Optional[int] = None,
disabled: bool = False,
) -> t.Callable[[t.Callable[[ViewT, Button, ViewContextT], t.Any]], Button]:
) -> t.Callable[[t.Callable[[ViewT, Button, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""A decorator to transform a coroutine function into a Discord UI Button's callback.
This must be inside a subclass of View.
Expand All @@ -199,7 +199,7 @@ def button(
The decorated callback coroutine function.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, Button, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("button must decorate coroutine function.")
item = Button(
Expand Down
4 changes: 2 additions & 2 deletions miru/select/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def channel_select(
max_values: int = 1,
disabled: bool = False,
row: t.Optional[int] = None,
) -> t.Callable[[t.Callable[[ViewT, ChannelSelect, ViewContextT], t.Any]], ChannelSelect]:
) -> t.Callable[[t.Callable[[ViewT, ChannelSelect, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""
A decorator to transform a function into a Discord UI ChannelSelectMenu's callback. This must be inside a subclass of View.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, ChannelSelect, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("channel_select must decorate coroutine function.")

Expand Down
4 changes: 2 additions & 2 deletions miru/select/mentionable.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def mentionable_select(
max_values: int = 1,
disabled: bool = False,
row: t.Optional[int] = None,
) -> t.Callable[[t.Callable[[ViewT, MentionableSelect, ViewContextT], t.Any]], MentionableSelect]:
) -> t.Callable[[t.Callable[[ViewT, MentionableSelect, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""
A decorator to transform a function into a Discord UI MentionableSelectMenu's callback.
This must be inside a subclass of View.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, MentionableSelect, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("mentionable_select must decorate coroutine function.")

Expand Down
4 changes: 2 additions & 2 deletions miru/select/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def role_select(
max_values: int = 1,
disabled: bool = False,
row: t.Optional[int] = None,
) -> t.Callable[[t.Callable[[ViewT, RoleSelect, ViewContextT], t.Any]], RoleSelect]:
) -> t.Callable[[t.Callable[[ViewT, RoleSelect, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""
A decorator to transform a function into a Discord UI RoleSelectMenu's callback. This must be inside a subclass of View.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, RoleSelect, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("role_select must decorate coroutine function.")

Expand Down
4 changes: 2 additions & 2 deletions miru/select/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ def text_select(
max_values: int = 1,
disabled: bool = False,
row: t.Optional[int] = None,
) -> t.Callable[[t.Callable[[ViewT, TextSelect, ViewContextT], t.Any]], TextSelect]:
) -> t.Callable[[t.Callable[[ViewT, TextSelect, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""
A decorator to transform a function into a Discord UI TextSelectMenu's callback. This must be inside a subclass of View.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, TextSelect, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("text_select must decorate coroutine function.")

Expand Down
4 changes: 2 additions & 2 deletions miru/select/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def user_select(
max_values: int = 1,
disabled: bool = False,
row: t.Optional[int] = None,
) -> t.Callable[[t.Callable[[ViewT, UserSelect, ViewContextT], t.Any]], UserSelect]:
) -> t.Callable[[t.Callable[[ViewT, UserSelect, ViewContextT], t.Awaitable[None]]], DecoratedItem]:
"""
A decorator to transform a function into a Discord UI UserSelectMenu's callback. This must be inside a subclass of View.
"""

def decorator(func: t.Callable[..., t.Any]) -> t.Any:
def decorator(func: t.Callable[[ViewT, UserSelect, ViewContextT], t.Awaitable[None]]) -> DecoratedItem:
if not inspect.iscoroutinefunction(func):
raise TypeError("user_select must decorate coroutine function.")

Expand Down

0 comments on commit b1fec52

Please sign in to comment.