|
1 | 1 | """ |
2 | 2 | Internal module for type-hinting aliases. Ensures single common definitions. |
3 | 3 | """ |
| 4 | +from enum import Enum |
| 5 | +import typing |
| 6 | +from typing import Callable, Literal, Self, TypeVar, ParamSpec, Protocol |
4 | 7 |
|
5 | 8 | import discord |
6 | | -import typing |
7 | 9 |
|
8 | | -T = typing.TypeVar('T') |
| 10 | +T = TypeVar('T') |
| 11 | +P = ParamSpec('P') |
| 12 | + |
| 13 | +AnyChannel = (discord.abc.GuildChannel | discord.TextChannel | discord.VoiceChannel | discord.StageChannel |
| 14 | + | discord.DMChannel | discord.Thread | discord.GroupChannel) |
| 15 | + |
| 16 | + |
| 17 | +class Wrapper(Protocol[P, T]): |
| 18 | + __wrapped__: Callable[P, T] |
| 19 | + |
| 20 | + def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: |
| 21 | + ... |
| 22 | + |
| 23 | + |
| 24 | +class FnWithOld(Protocol[P, T]): |
| 25 | + __old__: Callable[P, T] | None |
| 26 | + |
| 27 | + def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: |
| 28 | + ... |
| 29 | + |
| 30 | + |
| 31 | +class Undef(Enum): |
| 32 | + undefined = None |
| 33 | + |
| 34 | + |
| 35 | +undefined: Literal[Undef.undefined] = Undef.undefined |
9 | 36 |
|
10 | | -Callback = typing.Callable[..., typing.Coroutine[None, None, None]] |
11 | | -AnyChannel = (discord.TextChannel | discord.CategoryChannel | discord.abc.GuildChannel |
12 | | - | discord.abc.PrivateChannel | discord.Thread) |
13 | 37 |
|
14 | 38 | if typing.TYPE_CHECKING: |
15 | 39 | from discord.types import ( |
16 | | - role, gateway, appinfo, user, guild, emoji, channel, message, sticker, # noqa: F401 |
17 | | - scheduled_event, member # noqa: F401 |
| 40 | + role, gateway, appinfo, user, guild, emoji, channel, message, sticker, snowflake, # noqa: F401 |
| 41 | + scheduled_event, member, poll # noqa: F401 |
18 | 42 | ) |
19 | 43 |
|
20 | 44 | AnyChannelJson = channel.VoiceChannel | channel.TextChannel | channel.DMChannel | channel.CategoryChannel |
21 | 45 | else: |
22 | 46 | class OpenNamespace: |
23 | | - def __getattr__(self, item: str) -> typing.Self: |
| 47 | + def __getattr__(self, item: str) -> Self: |
24 | 48 | return self |
25 | 49 |
|
26 | | - def __subclasscheck__(self, subclass: type) -> typing.Literal[True]: |
| 50 | + def __subclasscheck__(self, subclass: type) -> Literal[True]: |
27 | 51 | return True |
28 | 52 |
|
29 | 53 | def __or__(self, other: T) -> T: |
|
0 commit comments