73
73
from collections import abc as collections
74
74
75
75
import hikari
76
+ import typing_extensions
76
77
from alluka import abc as alluka
77
78
78
79
if typing .TYPE_CHECKING :
91
92
_MessageCommandT = typing .TypeVar ("_MessageCommandT" , bound = "MessageCommand[typing.Any]" )
92
93
_MetaEventSigT = typing .TypeVar ("_MetaEventSigT" , bound = "MetaEventSig" )
93
94
95
+ _P = typing_extensions .ParamSpec ("_P" )
94
96
_T = typing .TypeVar ("_T" )
95
97
_AppCommandContextT = typing .TypeVar ("_AppCommandContextT" , bound = "AppCommandContext" )
96
98
_CommandCallbackSigT = typing .TypeVar ("_CommandCallbackSigT" , bound = "CommandCallbackSig" )
102
104
"_MenuTypeT" , typing .Literal [hikari .CommandType .USER ], typing .Literal [hikari .CommandType .MESSAGE ]
103
105
)
104
106
107
+ _MaybeAwaitable = typing .Union [collections .Callable [_P , _CoroT [_T ]], collections .Callable [_P , _T ]]
108
+ _AutocompleteCallbackSig = collections .Callable [typing_extensions .Concatenate ["AutocompleteContext" , _P ], _CoroT [None ]]
105
109
106
- AutocompleteCallbackSig = collections . Callable [..., _CoroT [ None ] ]
110
+ AutocompleteCallbackSig = _AutocompleteCallbackSig [...]
107
111
"""Type hint of the callback an autocomplete callback should have.
108
112
109
113
This will be called when handling autocomplete and should be an asynchronous
112
116
autocomplete type), returns [None][] and may use dependency injection.
113
117
"""
114
118
115
-
116
- CheckSig = typing . Union [ collections . Callable [..., _CoroT [ bool ]], collections . Callable [..., bool ] ]
119
+ _CheckSig = _MaybeAwaitable [ typing_extensions . Concatenate [ _ContextT_contra , _P ], bool ]
120
+ CheckSig = _CheckSig [ _ContextT_contra , ... ]
117
121
"""Type hint of a general context check used with Tanjun [tanjun.abc.ExecutableCommand][] classes.
118
122
119
123
This may be registered with a [tanjun.abc.ExecutableCommand][] to add a rule
124
128
current context shouldn't lead to an execution.
125
129
"""
126
130
127
- CommandCallbackSig = collections .Callable [..., _CoroT [None ]]
131
+ AnyCheckSig = _CheckSig ["Context" , ...]
132
+
133
+ MessageCheckSig = _CheckSig ["MessageContext" , ...]
134
+
135
+ SlashCheckSig = _CheckSig ["SlashContext" , ...]
136
+
137
+
138
+ _CommandCallbackSig = collections .Callable [typing_extensions .Concatenate [_ContextT_contra , _P ], None ]
139
+
140
+ _MenuValueT = typing .TypeVar ("_MenuValueT" , hikari .User , hikari .InteractionMember )
141
+ _ManuCallbackSig = collections .Callable [typing_extensions .Concatenate [_ContextT_contra , _MenuValueT , _P ], None ]
142
+ MenuCallbackSig = _ManuCallbackSig ["MenuContext" , _MenuValueT , ...]
143
+ """Type hint of a context menu command callback.
144
+
145
+ This is guaranteed two positional; arguments of type [tanjun.abc.MenuContext][]
146
+ and either `hikari.User | hikari.InteractionMember` and/or
147
+ [hikari.messages.Message][] dependent on the type(s) of menu this is.
148
+ """
149
+
150
+ MessageCallbackSig = _CommandCallbackSig ["MessageContext" , ...]
151
+ SlashCallbackSig = _CommandCallbackSig ["SlashContext" , ...]
152
+
153
+ CommandCallbackSig = _CommandCallbackSig ["Context" , ...]
128
154
"""Type hint of the callback a callable [tanjun.abc.ExecutableCommand][] instance will operate on.
129
155
130
156
This will be called when executing a command and will need to take one
136
162
This will have to be asynchronous.
137
163
"""
138
164
165
+ _ErrorHookSig = _MaybeAwaitable [typing_extensions .Concatenate [_ContextT_contra , Exception , _P ], typing .Optional [bool ]]
139
166
140
- ErrorHookSig = typing .Union [
141
- collections .Callable [..., typing .Optional [bool ]], collections .Callable [..., _CoroT [typing .Optional [bool ]]]
142
- ]
167
+ ErrorHookSig = _ErrorHookSig [_ContextT_contra , ...]
143
168
"""Type hint of the callback used as a unexpected command error hook.
144
169
145
170
This will be called whenever an unexpected [Exception][] is raised during the
153
178
[False][] is returned to indicate that the exception should be re-raised.
154
179
"""
155
180
181
+ _HookSig = _MaybeAwaitable [typing_extensions .Concatenate [_ContextT_contra , _P ], None ]
156
182
157
- HookSig = typing . Union [ collections . Callable [..., None ], collections . Callable [..., _CoroT [ None ]] ]
183
+ HookSig = _HookSig [ _ContextT_contra , ... ]
158
184
"""Type hint of the callback used as a general command hook.
159
185
160
186
!!! note
163
189
are passed dependent on the type of hook this is being registered as.
164
190
"""
165
191
166
- ListenerCallbackSig = collections .Callable [..., _CoroT [None ]]
192
+ _ListenerCallbackSig = collections .Callable [typing_extensions .Concatenate [Exception , _P ], _CoroT [None ]]
193
+
194
+ ListenerCallbackSig = _ListenerCallbackSig [...]
167
195
"""Type hint of a hikari event manager callback.
168
196
169
197
This is guaranteed one positional arg of type [hikari.events.base_events.Event][]
170
198
regardless of implementation and must be a coruotine function which returns [None][].
171
199
"""
172
200
173
- MenuCommandCallbackSig = collections .Callable [..., _CoroT [None ]]
174
- """Type hint of a context menu command callback.
175
-
176
- This is guaranteed two positional; arguments of type [tanjun.abc.MenuContext][]
177
- and either `hikari.User | hikari.InteractionMember` and/or
178
- [hikari.messages.Message][] dependent on the type(s) of menu this is.
179
- """
180
-
181
- MetaEventSig = typing .Union [collections .Callable [..., _CoroT [None ]], collections .Callable [..., None ]]
201
+ MetaEventSig = _MaybeAwaitable [..., None ]
182
202
"""Type hint of a client callback.
183
203
184
204
The positional arguments this is guaranteed depend on the event name its being
@@ -2383,7 +2403,7 @@ class ExecutableCommand(abc.ABC, typing.Generic[_ContextT_co]):
2383
2403
2384
2404
@property
2385
2405
@abc .abstractmethod
2386
- def checks (self ) -> collections .Collection [CheckSig ]:
2406
+ def checks (self ) -> collections .Collection [CheckSig [ _ContextT_co ] ]:
2387
2407
"""Collection of checks that must be met before the command can be executed."""
2388
2408
2389
2409
@property
@@ -2440,7 +2460,7 @@ def set_hooks(self: _T, hooks: typing.Optional[Hooks[_ContextT_co]], /) -> _T:
2440
2460
"""
2441
2461
2442
2462
@abc .abstractmethod
2443
- def add_check (self : _T , check : CheckSig , / ) -> _T : # TODO: remove or add with_check?
2463
+ def add_check (self : _T , check : CheckSig [ _ContextT_co ] , / ) -> _T : # TODO: remove or add with_check?
2444
2464
"""Add a check to the command.
2445
2465
2446
2466
Parameters
@@ -2455,7 +2475,7 @@ def add_check(self: _T, check: CheckSig, /) -> _T: # TODO: remove or add with_c
2455
2475
"""
2456
2476
2457
2477
@abc .abstractmethod
2458
- def remove_check (self : _T , check : CheckSig , / ) -> _T :
2478
+ def remove_check (self : _T , check : CheckSig [ _ContextT_co ] , / ) -> _T :
2459
2479
"""Remove a check from the command.
2460
2480
2461
2481
Parameters
0 commit comments