Skip to content

Commit 59b9415

Browse files
committed
🏷️ Even more using Protocol
1 parent 101bf55 commit 59b9415

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

discord/bot.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
TypeVar,
4848
)
4949

50+
from typing_extensions import Protocol
51+
5052
from .client import Client
5153
from .cog import CogMixin
5254
from .commands import (
@@ -69,6 +71,8 @@
6971
from .utils.private import async_all, maybe_awaitable
7072

7173
if TYPE_CHECKING:
74+
from typing import Unpack
75+
7276
from .interactions import ComponentInteraction, ModalInteraction
7377
from .member import Member
7478

@@ -1101,11 +1105,10 @@ async def invoke_application_command(self, ctx: ApplicationContext) -> None:
11011105
def _bot(self) -> Bot | AutoShardedBot: ...
11021106

11031107

1104-
T = TypeVar("T")
1108+
class ComponentListener(Protocol):
1109+
async def __call__(self, interaction: ComponentInteraction[Any]) -> Any: ...
11051110

1106-
Listener: TypeAlias = Callable[[T], Coroutine[Any, Any, Any]] # pyright: ignore[reportExplicitAny]
11071111

1108-
ComponentListener: TypeAlias = "Listener[ComponentInteraction]"
11091112
CL_t = TypeVar("CL_t", bound=ComponentListener)
11101113

11111114

@@ -1222,7 +1225,10 @@ def wrapper(func: CL_t) -> CL_t:
12221225
def _bot(self) -> Bot | AutoShardedBot: ...
12231226

12241227

1225-
ModalListener: TypeAlias = "Listener[ModalInteraction]"
1228+
class ModalListener(Protocol):
1229+
async def __call__(self, interaction: ModalInteraction[Unpack[tuple[Any, ...]]]) -> Any: ...
1230+
1231+
12261232
ML_t = TypeVar("ML_t", bound=ModalListener)
12271233

12281234

examples/components/simple_modal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dotenv import load_dotenv
44

55
import discord
6-
from discord import components
6+
from discord import Interaction, components
77

88
load_dotenv()
99

0 commit comments

Comments
 (0)