Move event listeners and client callbacks API to use AbstractComponentLoader#794
Move event listeners and client callbacks API to use AbstractComponentLoader#794davfsa wants to merge 3 commits intoCursed-Solutions:masterfrom
Conversation
Switch to using better method to get python source-code
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def with_listener( |
There was a problem hiding this comment.
Not entirely happy with this change, as it feels a bit of an outliner now
| .. deprecated :: 2.15 | ||
| This argument used to be `name`: | ||
|
|
||
| The name this callback is being registered to. | ||
|
|
||
| This is case-insensitive. |
There was a problem hiding this comment.
Let Let me know if you a different way to document this deprecation
| ```py | ||
| client = tanjun.Client.from_rest_bot(bot) | ||
|
|
||
| @client.with_client_callback("closed") |
There was a problem hiding this comment.
Forgot to change the one in client, will do later :)
| return lambda callback: ClientCallback(callback, name=name) | ||
|
|
||
|
|
||
| class ClientCallback(typing.Generic[_ClientCallbackSigT], components.AbstractComponentLoader): |
There was a problem hiding this comment.
These types shouldn't be publicly exposed or really used anywhere else (and this stuff can all be define in components.py since that's the only place where load_from_scope is relevant).
| component.add_listener(event_type, self._callback) | ||
|
|
||
|
|
||
| @typing.runtime_checkable |
There was a problem hiding this comment.
These protocols seems kinda unnecessary, this stuff only needs to work with the standard Component impl
|
|
||
| def as_client_callback( | ||
| name: typing.Union[str, tanjun.ClientCallbackNames] | ||
| ) -> collections.Callable[[_ClientCallbackSigT], ClientCallback[_ClientCallbackSigT]]: |
There was a problem hiding this comment.
This should just be typed as returning Callable[[_ClientCallbackSigT], _ClientCallbackSigT]
| self._client.remove_client_callback(name, callback) | ||
|
|
||
| @typing.overload | ||
| def with_client_callback( |
There was a problem hiding this comment.
The as_ load_from_scope functions shouldn't replace these decorators, they should just be added alongside this (and in the case of event listeners just directly call the with_listener instead of add_listener to allow for type hint analysis)
Summary
Brings the API for event listeners and client callbacks more in-line with how slash commands and message commands are done.
Checklist
noxand all the pipelines have passed.