mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 18:33:02 +00:00
Add positional-only arguments in more places
This commit is contained in:
@ -227,12 +227,16 @@ class BotBase(GroupMixin):
|
||||
self.add_check(func) # type: ignore
|
||||
return func
|
||||
|
||||
def add_check(self, func: Check, *, call_once: bool = False) -> None:
|
||||
def add_check(self, func: Check, /, *, call_once: bool = False) -> None:
|
||||
"""Adds a global check to the bot.
|
||||
|
||||
This is the non-decorator interface to :meth:`.check`
|
||||
and :meth:`.check_once`.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
func
|
||||
@ -247,12 +251,16 @@ class BotBase(GroupMixin):
|
||||
else:
|
||||
self._checks.append(func)
|
||||
|
||||
def remove_check(self, func: Check, *, call_once: bool = False) -> None:
|
||||
def remove_check(self, func: Check, /, *, call_once: bool = False) -> None:
|
||||
"""Removes a global check from the bot.
|
||||
|
||||
This function is idempotent and will not raise an exception
|
||||
if the function is not in the global checks.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
func
|
||||
@ -510,7 +518,7 @@ class BotBase(GroupMixin):
|
||||
|
||||
# cogs
|
||||
|
||||
def add_cog(self, cog: Cog, *, override: bool = False) -> None:
|
||||
def add_cog(self, cog: Cog, /, *, override: bool = False) -> None:
|
||||
"""Adds a "cog" to the bot.
|
||||
|
||||
A cog is a class that has its own event listeners and commands.
|
||||
@ -520,6 +528,10 @@ class BotBase(GroupMixin):
|
||||
:exc:`.ClientException` is raised when a cog with the same name
|
||||
is already loaded.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``cog`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
cog: :class:`.Cog`
|
||||
@ -554,11 +566,15 @@ class BotBase(GroupMixin):
|
||||
cog = cog._inject(self)
|
||||
self.__cogs[cog_name] = cog
|
||||
|
||||
def get_cog(self, name: str) -> Optional[Cog]:
|
||||
def get_cog(self, name: str, /) -> Optional[Cog]:
|
||||
"""Gets the cog instance requested.
|
||||
|
||||
If the cog is not found, ``None`` is returned instead.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``name`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
name: :class:`str`
|
||||
@ -573,7 +589,7 @@ class BotBase(GroupMixin):
|
||||
"""
|
||||
return self.__cogs.get(name)
|
||||
|
||||
def remove_cog(self, name: str) -> Optional[Cog]:
|
||||
def remove_cog(self, name: str, /) -> Optional[Cog]:
|
||||
"""Removes a cog from the bot and returns it.
|
||||
|
||||
All registered commands and event listeners that the
|
||||
@ -581,6 +597,10 @@ class BotBase(GroupMixin):
|
||||
|
||||
If no cog is found then this method has no effect.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``name`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
name: :class:`str`
|
||||
|
@ -170,6 +170,10 @@ class Context(discord.abc.Messageable, Generic[BotT]):
|
||||
You must take care in passing the proper arguments when
|
||||
using this function.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``command`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
command: :class:`.Command`
|
||||
|
@ -408,13 +408,17 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
|
||||
self.params = get_signature_parameters(function, globalns)
|
||||
|
||||
def add_check(self, func: Check) -> None:
|
||||
def add_check(self, func: Check, /) -> None:
|
||||
"""Adds a check to the command.
|
||||
|
||||
This is the non-decorator interface to :func:`.check`.
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
func
|
||||
@ -423,7 +427,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
|
||||
self.checks.append(func)
|
||||
|
||||
def remove_check(self, func: Check) -> None:
|
||||
def remove_check(self, func: Check, /) -> None:
|
||||
"""Removes a check from the command.
|
||||
|
||||
This function is idempotent and will not raise an exception
|
||||
@ -431,6 +435,10 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
func
|
||||
@ -1156,7 +1164,7 @@ class GroupMixin(Generic[CogT]):
|
||||
command.recursively_remove_all_commands()
|
||||
self.remove_command(command.name)
|
||||
|
||||
def add_command(self, command: Command[CogT, Any, Any]) -> 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
|
||||
@ -1165,6 +1173,10 @@ class GroupMixin(Generic[CogT]):
|
||||
.. versionchanged:: 1.4
|
||||
Raise :exc:`.CommandRegistrationError` instead of generic :exc:`.ClientException`
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``command`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
command: :class:`Command`
|
||||
@ -1194,12 +1206,16 @@ class GroupMixin(Generic[CogT]):
|
||||
raise CommandRegistrationError(alias, alias_conflict=True)
|
||||
self.all_commands[alias] = command
|
||||
|
||||
def remove_command(self, name: str) -> Optional[Command[CogT, Any, Any]]:
|
||||
def remove_command(self, name: str, /) -> Optional[Command[CogT, Any, Any]]:
|
||||
"""Remove a :class:`.Command` from the internal list
|
||||
of commands.
|
||||
|
||||
This could also be used as a way to remove aliases.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``name`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
name: :class:`str`
|
||||
@ -1247,7 +1263,7 @@ class GroupMixin(Generic[CogT]):
|
||||
if isinstance(command, GroupMixin):
|
||||
yield from command.walk_commands()
|
||||
|
||||
def get_command(self, name: str) -> Optional[Command[CogT, Any, Any]]:
|
||||
def get_command(self, name: str, /) -> Optional[Command[CogT, Any, Any]]:
|
||||
"""Get a :class:`.Command` from the internal list
|
||||
of commands.
|
||||
|
||||
@ -1257,6 +1273,10 @@ class GroupMixin(Generic[CogT]):
|
||||
the subcommand ``bar`` of the group command ``foo``. If a
|
||||
subcommand is not found then ``None`` is returned just as usual.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``name`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
name: :class:`str`
|
||||
|
@ -343,12 +343,16 @@ class HelpCommand:
|
||||
bot.remove_command(self._command_impl.name)
|
||||
self._command_impl._eject_cog()
|
||||
|
||||
def add_check(self, func):
|
||||
def add_check(self, func, /):
|
||||
"""
|
||||
Adds a check to the help command.
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
func
|
||||
@ -357,7 +361,7 @@ class HelpCommand:
|
||||
|
||||
self._command_impl.add_check(func)
|
||||
|
||||
def remove_check(self, func):
|
||||
def remove_check(self, func, /):
|
||||
"""
|
||||
Removes a check from the help command.
|
||||
|
||||
@ -366,6 +370,10 @@ class HelpCommand:
|
||||
|
||||
.. versionadded:: 1.4
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
|
||||
``func`` parameter is now positional-only.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
func
|
||||
|
Reference in New Issue
Block a user