mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-11 16:29:49 +00:00
[commands] Make GroupMixin Generic
This commit is contained in:
parent
6c36df6c11
commit
166152647c
@ -1125,7 +1125,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
finally:
|
||||
ctx.command = original
|
||||
|
||||
class GroupMixin:
|
||||
class GroupMixin(Generic[CogT]):
|
||||
"""A mixin that implements common functionality for classes that behave
|
||||
similar to :class:`.Group` and are allowed to register commands.
|
||||
|
||||
@ -1139,12 +1139,12 @@ class GroupMixin:
|
||||
"""
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
case_insensitive = kwargs.get('case_insensitive', False)
|
||||
self.all_commands: Dict[str, Command] = _CaseInsensitiveDict() if case_insensitive else {}
|
||||
self.all_commands: Dict[str, Command[CogT, Any, Any]] = _CaseInsensitiveDict() if case_insensitive else {}
|
||||
self.case_insensitive: bool = case_insensitive
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def commands(self) -> Set[Command]:
|
||||
def commands(self) -> Set[Command[CogT, Any, Any]]:
|
||||
"""Set[:class:`.Command`]: A unique set of commands without aliases that are registered."""
|
||||
return set(self.all_commands.values())
|
||||
|
||||
@ -1154,7 +1154,7 @@ class GroupMixin:
|
||||
command.recursively_remove_all_commands()
|
||||
self.remove_command(command.name)
|
||||
|
||||
def add_command(self, command: Command) -> None:
|
||||
def add_command(self, command: Command[CogT, Any, Any]) -> None:
|
||||
"""Adds a :class:`.Command` into the internal list of commands.
|
||||
|
||||
This is usually not called, instead the :meth:`~.GroupMixin.command` or
|
||||
@ -1192,7 +1192,7 @@ class GroupMixin:
|
||||
raise CommandRegistrationError(alias, alias_conflict=True)
|
||||
self.all_commands[alias] = command
|
||||
|
||||
def remove_command(self, name: str) -> Optional[Command]:
|
||||
def remove_command(self, name: str) -> Optional[Command[CogT, Any, Any]]:
|
||||
"""Remove a :class:`.Command` from the internal list
|
||||
of commands.
|
||||
|
||||
@ -1229,7 +1229,7 @@ class GroupMixin:
|
||||
self.all_commands[alias] = cmd
|
||||
return command
|
||||
|
||||
def walk_commands(self) -> Generator[Command, None, None]:
|
||||
def walk_commands(self) -> Generator[Command[CogT, Any, Any], None, None]:
|
||||
"""An iterator that recursively walks through all commands and subcommands.
|
||||
|
||||
.. versionchanged:: 1.4
|
||||
@ -1245,7 +1245,7 @@ class GroupMixin:
|
||||
if isinstance(command, GroupMixin):
|
||||
yield from command.walk_commands()
|
||||
|
||||
def get_command(self, name: str) -> Optional[Command]:
|
||||
def get_command(self, name: str) -> Optional[Command[CogT, Any, Any]]:
|
||||
"""Get a :class:`.Command` from the internal list
|
||||
of commands.
|
||||
|
||||
@ -1292,7 +1292,13 @@ class GroupMixin:
|
||||
cls: Type[Command[CogT, P, T]] = ...,
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[Callable[Concatenate[ContextT, P], Coro[T]]], Command[CogT, P, T]]:
|
||||
) -> Callable[
|
||||
[
|
||||
Union[
|
||||
Callable[Concatenate[CogT, ContextT, P], Coro[T]],
|
||||
Callable[Concatenate[ContextT, P], Coro[T]],
|
||||
]
|
||||
], Command[CogT, P, T]]:
|
||||
...
|
||||
|
||||
@overload
|
||||
@ -1335,7 +1341,12 @@ class GroupMixin:
|
||||
cls: Type[Group[CogT, P, T]] = ...,
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> Callable[[Callable[Concatenate[ContextT, P], Coro[T]]], Group[CogT, P, T]]:
|
||||
) -> Callable[[
|
||||
Union[
|
||||
Callable[Concatenate[CogT, ContextT, P], Coro[T]],
|
||||
Callable[Concatenate[ContextT, P], Coro[T]]
|
||||
]
|
||||
], Group[CogT, P, T]]:
|
||||
...
|
||||
|
||||
@overload
|
||||
@ -1371,7 +1382,7 @@ class GroupMixin:
|
||||
|
||||
return decorator
|
||||
|
||||
class Group(GroupMixin, Command[CogT, P, T]):
|
||||
class Group(GroupMixin[CogT], Command[CogT, P, T]):
|
||||
"""A class that implements a grouping protocol for commands to be
|
||||
executed as subcommands.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user