Browse Source

Don't recreate ItemCallbackType

pull/10262/head
Rapptz 5 days ago
parent
commit
8c1886799d
  1. 3
      discord/ui/action_row.py
  2. 7
      discord/ui/button.py
  3. 6
      discord/ui/container.py
  4. 7
      discord/ui/item.py
  5. 5
      discord/ui/select.py

3
discord/ui/action_row.py

@ -41,7 +41,7 @@ from typing import (
overload, overload,
) )
from .item import I, Item from .item import Item, ContainedItemCallbackType as ItemCallbackType
from .button import Button, button as _button from .button import Button, button as _button
from .select import select as _select, Select, UserSelect, RoleSelect, ChannelSelect, MentionableSelect from .select import select as _select, Select, UserSelect, RoleSelect, ChannelSelect, MentionableSelect
from ..components import ActionRow as ActionRowComponent from ..components import ActionRow as ActionRowComponent
@ -66,7 +66,6 @@ if TYPE_CHECKING:
from ..components import SelectOption from ..components import SelectOption
from ..interactions import Interaction from ..interactions import Interaction
ItemCallbackType = Callable[['S', Interaction[Any], I], Coroutine[Any, Any, Any]]
SelectCallbackDecorator = Callable[[ItemCallbackType['S', BaseSelectT]], BaseSelectT] SelectCallbackDecorator = Callable[[ItemCallbackType['S', BaseSelectT]], BaseSelectT]
S = TypeVar('S', bound='ActionRow', covariant=True) S = TypeVar('S', bound='ActionRow', covariant=True)

7
discord/ui/button.py

@ -25,12 +25,12 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
import copy import copy
from typing import Any, Callable, Coroutine, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Union from typing import Callable, Literal, Optional, TYPE_CHECKING, Tuple, TypeVar, Union
import inspect import inspect
import os import os
from .item import Item, I from .item import Item, ContainedItemCallbackType as ItemCallbackType
from ..enums import ButtonStyle, ComponentType from ..enums import ButtonStyle, ComponentType
from ..partial_emoji import PartialEmoji, _EmojiTag from ..partial_emoji import PartialEmoji, _EmojiTag
from ..components import Button as ButtonComponent from ..components import Button as ButtonComponent
@ -46,11 +46,8 @@ if TYPE_CHECKING:
from .view import BaseView from .view import BaseView
from .action_row import ActionRow from .action_row import ActionRow
from ..emoji import Emoji from ..emoji import Emoji
from ..interactions import Interaction
from ..types.components import ButtonComponent as ButtonComponentPayload from ..types.components import ButtonComponent as ButtonComponentPayload
ItemCallbackType = Callable[['S', Interaction[Any], I], Coroutine[Any, Any, Any]]
S = TypeVar('S', bound='Union[BaseView, ActionRow]', covariant=True) S = TypeVar('S', bound='Union[BaseView, ActionRow]', covariant=True)
V = TypeVar('V', bound='BaseView', covariant=True) V = TypeVar('V', bound='BaseView', covariant=True)

6
discord/ui/container.py

@ -21,13 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
""" """
from __future__ import annotations from __future__ import annotations
import copy import copy
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
Callable,
ClassVar, ClassVar,
Coroutine, Coroutine,
Dict, Dict,
@ -39,7 +39,7 @@ from typing import (
Union, Union,
) )
from .item import Item, I from .item import Item, ContainedItemCallbackType as ItemCallbackType
from .view import _component_to_item, LayoutView from .view import _component_to_item, LayoutView
from ..enums import ComponentType from ..enums import ComponentType
from ..utils import get as _utils_get from ..utils import get as _utils_get
@ -51,8 +51,6 @@ if TYPE_CHECKING:
from ..components import Container as ContainerComponent from ..components import Container as ContainerComponent
from ..interactions import Interaction from ..interactions import Interaction
ItemCallbackType = Callable[['S', Interaction[Any], I], Coroutine[Any, Any, Any]]
S = TypeVar('S', bound='Container', covariant=True) S = TypeVar('S', bound='Container', covariant=True)
V = TypeVar('V', bound='LayoutView', covariant=True) V = TypeVar('V', bound='LayoutView', covariant=True)

7
discord/ui/item.py

@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
import copy import copy
from typing import Any, Callable, Coroutine, Dict, Generic, Optional, TYPE_CHECKING, Tuple, Type, TypeVar from typing import Any, Callable, Coroutine, Dict, Generic, Optional, TYPE_CHECKING, Union, Tuple, Type, TypeVar
from ..interactions import Interaction from ..interactions import Interaction
from .._types import ClientT from .._types import ClientT
@ -42,10 +42,15 @@ if TYPE_CHECKING:
from ..enums import ComponentType from ..enums import ComponentType
from .view import BaseView from .view import BaseView
from ..components import Component from ..components import Component
from .action_row import ActionRow
from .container import Container
I = TypeVar('I', bound='Item[Any]') I = TypeVar('I', bound='Item[Any]')
V = TypeVar('V', bound='BaseView', covariant=True) V = TypeVar('V', bound='BaseView', covariant=True)
ContainerType = Union['BaseView', 'ActionRow', 'Container']
C = TypeVar('C', bound=ContainerType, covariant=True)
ItemCallbackType = Callable[[V, Interaction[Any], I], Coroutine[Any, Any, Any]] ItemCallbackType = Callable[[V, Interaction[Any], I], Coroutine[Any, Any, Any]]
ContainedItemCallbackType = Callable[[C, Interaction[Any], I], Coroutine[Any, Any, Any]]
class Item(Generic[V]): class Item(Generic[V]):

5
discord/ui/select.py

@ -25,7 +25,6 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
from typing import ( from typing import (
Any, Any,
Coroutine,
List, List,
Literal, Literal,
Optional, Optional,
@ -43,7 +42,7 @@ from contextvars import ContextVar
import inspect import inspect
import os import os
from .item import Item, I from .item import Item, ContainedItemCallbackType as ItemCallbackType
from ..enums import ChannelType, ComponentType, SelectDefaultValueType from ..enums import ChannelType, ComponentType, SelectDefaultValueType
from ..partial_emoji import PartialEmoji from ..partial_emoji import PartialEmoji
from ..emoji import Emoji from ..emoji import Emoji
@ -103,8 +102,6 @@ if TYPE_CHECKING:
Thread, Thread,
] ]
ItemCallbackType = Callable[['S', Interaction[Any], I], Coroutine[Any, Any, Any]]
S = TypeVar('S', bound='Union[BaseView, ActionRow]', covariant=True) S = TypeVar('S', bound='Union[BaseView, ActionRow]', covariant=True)
V = TypeVar('V', bound='BaseView', covariant=True) V = TypeVar('V', bound='BaseView', covariant=True)
BaseSelectT = TypeVar('BaseSelectT', bound='BaseSelect[Any]') BaseSelectT = TypeVar('BaseSelectT', bound='BaseSelect[Any]')

Loading…
Cancel
Save