mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Alter return-type of button/select decorators
This commit is contained in:
parent
22b06e7bf8
commit
d409ddd227
@ -234,7 +234,7 @@ def button(
|
||||
style: ButtonStyle = ButtonStyle.secondary,
|
||||
emoji: Optional[Union[str, Emoji, PartialEmoji]] = None,
|
||||
row: Optional[int] = None,
|
||||
) -> Callable[[ItemCallbackType], ItemCallbackType]:
|
||||
) -> Callable[[ItemCallbackType[V, Button[V]]], Button[V]]:
|
||||
"""A decorator that attaches a button to a component.
|
||||
|
||||
The function being decorated should have three parameters, ``self`` representing
|
||||
@ -271,7 +271,7 @@ def button(
|
||||
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
|
||||
"""
|
||||
|
||||
def decorator(func: ItemCallbackType) -> ItemCallbackType:
|
||||
def decorator(func: ItemCallbackType[V, Button[V]]) -> ItemCallbackType[V, Button[V]]:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
raise TypeError('button function must be a coroutine function')
|
||||
|
||||
@ -287,4 +287,4 @@ def button(
|
||||
}
|
||||
return func
|
||||
|
||||
return decorator
|
||||
return decorator # type: ignore
|
||||
|
@ -41,7 +41,7 @@ if TYPE_CHECKING:
|
||||
|
||||
I = TypeVar('I', bound='Item')
|
||||
V = TypeVar('V', bound='View', covariant=True)
|
||||
ItemCallbackType = Callable[[Any, I, Interaction], Coroutine[Any, Any, Any]]
|
||||
ItemCallbackType = Callable[[V, I, Interaction], Coroutine[Any, Any, Any]]
|
||||
|
||||
|
||||
class Item(Generic[V]):
|
||||
|
@ -31,7 +31,6 @@ from .item import Item, ItemCallbackType
|
||||
from ..enums import ComponentType
|
||||
from ..partial_emoji import PartialEmoji
|
||||
from ..emoji import Emoji
|
||||
from ..interactions import Interaction
|
||||
from ..utils import MISSING
|
||||
from ..components import (
|
||||
SelectOption,
|
||||
@ -301,7 +300,7 @@ def select(
|
||||
options: List[SelectOption] = MISSING,
|
||||
disabled: bool = False,
|
||||
row: Optional[int] = None,
|
||||
) -> Callable[[ItemCallbackType], ItemCallbackType]:
|
||||
) -> Callable[[ItemCallbackType[V, Select[V]]], Select[V]]:
|
||||
"""A decorator that attaches a select menu to a component.
|
||||
|
||||
The function being decorated should have three parameters, ``self`` representing
|
||||
@ -336,7 +335,7 @@ def select(
|
||||
Whether the select is disabled or not. Defaults to ``False``.
|
||||
"""
|
||||
|
||||
def decorator(func: ItemCallbackType) -> ItemCallbackType:
|
||||
def decorator(func: ItemCallbackType[V, Select[V]]) -> ItemCallbackType[V, Select[V]]:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
raise TypeError('select function must be a coroutine function')
|
||||
|
||||
@ -352,4 +351,4 @@ def select(
|
||||
}
|
||||
return func
|
||||
|
||||
return decorator
|
||||
return decorator # type: ignore
|
||||
|
@ -150,10 +150,10 @@ class View:
|
||||
|
||||
__discord_ui_view__: ClassVar[bool] = True
|
||||
__discord_ui_modal__: ClassVar[bool] = False
|
||||
__view_children_items__: ClassVar[List[ItemCallbackType]] = []
|
||||
__view_children_items__: ClassVar[List[ItemCallbackType[Any, Any]]] = []
|
||||
|
||||
def __init_subclass__(cls) -> None:
|
||||
children: List[ItemCallbackType] = []
|
||||
children: List[ItemCallbackType[Any, Any]] = []
|
||||
for base in reversed(cls.__mro__):
|
||||
for member in base.__dict__.values():
|
||||
if hasattr(member, '__discord_ui_model_type__'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user