mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-02 00:00: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,
|
style: ButtonStyle = ButtonStyle.secondary,
|
||||||
emoji: Optional[Union[str, Emoji, PartialEmoji]] = None,
|
emoji: Optional[Union[str, Emoji, PartialEmoji]] = None,
|
||||||
row: Optional[int] = None,
|
row: Optional[int] = None,
|
||||||
) -> Callable[[ItemCallbackType], ItemCallbackType]:
|
) -> Callable[[ItemCallbackType[V, Button[V]]], Button[V]]:
|
||||||
"""A decorator that attaches a button to a component.
|
"""A decorator that attaches a button to a component.
|
||||||
|
|
||||||
The function being decorated should have three parameters, ``self`` representing
|
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).
|
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):
|
if not inspect.iscoroutinefunction(func):
|
||||||
raise TypeError('button function must be a coroutine function')
|
raise TypeError('button function must be a coroutine function')
|
||||||
|
|
||||||
@ -287,4 +287,4 @@ def button(
|
|||||||
}
|
}
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator # type: ignore
|
||||||
|
@ -41,7 +41,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
I = TypeVar('I', bound='Item')
|
I = TypeVar('I', bound='Item')
|
||||||
V = TypeVar('V', bound='View', covariant=True)
|
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]):
|
class Item(Generic[V]):
|
||||||
|
@ -31,7 +31,6 @@ from .item import Item, ItemCallbackType
|
|||||||
from ..enums import ComponentType
|
from ..enums import ComponentType
|
||||||
from ..partial_emoji import PartialEmoji
|
from ..partial_emoji import PartialEmoji
|
||||||
from ..emoji import Emoji
|
from ..emoji import Emoji
|
||||||
from ..interactions import Interaction
|
|
||||||
from ..utils import MISSING
|
from ..utils import MISSING
|
||||||
from ..components import (
|
from ..components import (
|
||||||
SelectOption,
|
SelectOption,
|
||||||
@ -301,7 +300,7 @@ def select(
|
|||||||
options: List[SelectOption] = MISSING,
|
options: List[SelectOption] = MISSING,
|
||||||
disabled: bool = False,
|
disabled: bool = False,
|
||||||
row: Optional[int] = None,
|
row: Optional[int] = None,
|
||||||
) -> Callable[[ItemCallbackType], ItemCallbackType]:
|
) -> Callable[[ItemCallbackType[V, Select[V]]], Select[V]]:
|
||||||
"""A decorator that attaches a select menu to a component.
|
"""A decorator that attaches a select menu to a component.
|
||||||
|
|
||||||
The function being decorated should have three parameters, ``self`` representing
|
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``.
|
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):
|
if not inspect.iscoroutinefunction(func):
|
||||||
raise TypeError('select function must be a coroutine function')
|
raise TypeError('select function must be a coroutine function')
|
||||||
|
|
||||||
@ -352,4 +351,4 @@ def select(
|
|||||||
}
|
}
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
return decorator # type: ignore
|
||||||
|
@ -150,10 +150,10 @@ class View:
|
|||||||
|
|
||||||
__discord_ui_view__: ClassVar[bool] = True
|
__discord_ui_view__: ClassVar[bool] = True
|
||||||
__discord_ui_modal__: ClassVar[bool] = False
|
__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:
|
def __init_subclass__(cls) -> None:
|
||||||
children: List[ItemCallbackType] = []
|
children: List[ItemCallbackType[Any, Any]] = []
|
||||||
for base in reversed(cls.__mro__):
|
for base in reversed(cls.__mro__):
|
||||||
for member in base.__dict__.values():
|
for member in base.__dict__.values():
|
||||||
if hasattr(member, '__discord_ui_model_type__'):
|
if hasattr(member, '__discord_ui_model_type__'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user