Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ci/release-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Oct 29, 2023
2 parents 7aeb024 + 038a365 commit 5f6eddb
Show file tree
Hide file tree
Showing 66 changed files with 398 additions and 257 deletions.
1 change: 1 addition & 0 deletions changelog/1111.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow ``cls`` argument in select menu decorators (e.g. :func`ui.string_select`) to be specified by keyword instead of being positional-only.
1 change: 1 addition & 0 deletions changelog/1116.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Rewrite slash command signature evaluation to use the same mechanism as prefix command signatures. This should not have an impact on user code, but streamlines future changes.
1 change: 1 addition & 0 deletions changelog/1121.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :class:`Interaction` and subtypes accept the bot type as a generic parameter to denote the type returned by the :attr:`~Interaction.bot` and :attr:`~Interaction.client` properties.
1 change: 1 addition & 0 deletions changelog/1126.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make all "Supported Operations" container elements collapsible.
8 changes: 4 additions & 4 deletions disnake/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class Game(BaseActivity):
This is typically displayed via **Playing** on the official Discord client.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -487,7 +487,7 @@ class Streaming(BaseActivity):
This is typically displayed via **Streaming** on the official Discord client.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -597,7 +597,7 @@ def __hash__(self) -> int:
class Spotify(_BaseActivity):
"""Represents a Spotify listening activity from Discord.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -770,7 +770,7 @@ def party_id(self) -> str:
class CustomActivity(BaseActivity):
"""Represents a Custom activity from Discord.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def to_file(
class Asset(AssetMixin):
"""Represents a CDN asset on Discord.
.. container:: operations
.. collapse:: operations
.. describe:: str(x)
Expand Down
2 changes: 1 addition & 1 deletion disnake/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class AuditLogEntry(Hashable):
You can retrieve these via :meth:`Guild.audit_logs`,
or via the :func:`on_audit_log_entry_create` event.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
16 changes: 8 additions & 8 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def _single_delete_strategy(messages: Iterable[Message]) -> None:
class TextChannel(disnake.abc.Messageable, disnake.abc.GuildChannel, Hashable):
"""Represents a Discord guild text channel.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -1217,7 +1217,7 @@ def permissions_for(
class VoiceChannel(disnake.abc.Messageable, VocalGuildChannel):
"""Represents a Discord guild voice channel.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -1871,7 +1871,7 @@ class StageChannel(disnake.abc.Messageable, VocalGuildChannel):
.. versionadded:: 1.7
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -2696,7 +2696,7 @@ class CategoryChannel(disnake.abc.GuildChannel, Hashable):
These are useful to group channels to logical compartments.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -3145,7 +3145,7 @@ class ForumChannel(disnake.abc.GuildChannel, Hashable):
.. versionadded:: 2.5
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -4184,7 +4184,7 @@ def get_tag_by_name(self, name: str, /) -> Optional[ForumTag]:
class DMChannel(disnake.abc.Messageable, Hashable):
"""Represents a Discord direct message channel.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -4347,7 +4347,7 @@ def get_partial_message(self, message_id: int, /) -> PartialMessage:
class GroupChannel(disnake.abc.Messageable, Hashable):
"""Represents a Discord group channel.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -4506,7 +4506,7 @@ class PartialMessageable(disnake.abc.Messageable, Hashable):
.. versionadded:: 2.0
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Colour:
There is an alias for this called Color.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _EmbedAuthorProxy(Sized, Protocol):
class Embed:
"""Represents a Discord embed.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Emoji(_EmojiTag, AssetMixin):
Depending on the way this object was created, some of the attributes can
have a value of ``None``.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
3 changes: 1 addition & 2 deletions disnake/ext/commands/common_bot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import asyncio
import collections.abc
import importlib.machinery
import importlib.util
import logging
import os
Expand All @@ -19,8 +20,6 @@
from .cog import Cog

if TYPE_CHECKING:
import importlib.machinery

from ._types import CoroFunc
from .bot import AutoShardedBot, AutoShardedInteractionBot, Bot, InteractionBot
from .help import HelpCommand
Expand Down
49 changes: 11 additions & 38 deletions disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
)

import disnake
from disnake.utils import _generated, _overload_with_permissions
from disnake.utils import (
_generated,
_overload_with_permissions,
get_signature_parameters,
unwrap_function,
)

from ._types import _BaseCommand
from .cog import Cog
Expand Down Expand Up @@ -114,42 +119,6 @@
P = TypeVar("P")


def unwrap_function(function: Callable[..., Any]) -> Callable[..., Any]:
partial = functools.partial
while True:
if hasattr(function, "__wrapped__"):
function = function.__wrapped__
elif isinstance(function, partial):
function = function.func
else:
return function


def get_signature_parameters(
function: Callable[..., Any], globalns: Dict[str, Any]
) -> Dict[str, inspect.Parameter]:
signature = inspect.signature(function)
params = {}
cache: Dict[str, Any] = {}
eval_annotation = disnake.utils.evaluate_annotation
for name, parameter in signature.parameters.items():
annotation = parameter.annotation
if annotation is parameter.empty:
params[name] = parameter
continue
if annotation is None:
params[name] = parameter.replace(annotation=type(None))
continue

annotation = eval_annotation(annotation, globalns, globalns, cache)
if annotation is Greedy:
raise TypeError("Unparameterized Greedy[...] is disallowed in signature.")

params[name] = parameter.replace(annotation=annotation)

return params


def wrap_callback(coro):
@functools.wraps(coro)
async def wrapped(*args, **kwargs):
Expand Down Expand Up @@ -410,7 +379,11 @@ def callback(self, function: CommandCallback[CogT, Any, P, T]) -> None:
except AttributeError:
globalns = {}

self.params = get_signature_parameters(function, globalns)
params = get_signature_parameters(function, globalns)
for param in params.values():
if param.annotation is Greedy:
raise TypeError("Unparameterized Greedy[...] is disallowed in signature.")
self.params = params

def add_check(self, func: Check) -> None:
"""Adds a check to the command.
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/flag_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class FlagConverter(metaclass=FlagsMeta):
how this converter works, check the appropriate
:ref:`documentation <ext_commands_flag_converter>`.
.. container:: operations
.. collapse:: operations
.. describe:: iter(x)
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CommandSyncFlags(BaseFlags):
.. versionadded:: 2.7
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class Paginator:
"""A class that aids in paginating code blocks for Discord messages.
.. container:: operations
.. collapse:: operations
.. describe:: len(x)
Expand Down
Loading

0 comments on commit 5f6eddb

Please sign in to comment.