Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into refactor/slash-si…
Browse files Browse the repository at this point in the history
…gnature-unified
  • Loading branch information
shiftinv committed Oct 26, 2023
2 parents 4d5813a + b23786b commit 0bee9dc
Show file tree
Hide file tree
Showing 54 changed files with 262 additions and 139 deletions.
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
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
38 changes: 20 additions & 18 deletions disnake/ext/commands/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
Type,
TypeVar,
Union,
get_args,
get_origin,
)

Expand Down Expand Up @@ -110,17 +109,26 @@


def issubclass_(obj: Any, tp: Union[TypeT, Tuple[TypeT, ...]]) -> TypeGuard[TypeT]:
"""Similar to the builtin `issubclass`, but more lenient.
Can also handle unions (`issubclass(Union[int, str], int)`) and
generic types (`issubclass(X[T], X)`) in the first argument.
"""
if not isinstance(tp, (type, tuple)):
return False
elif not isinstance(obj, type):
# Assume we have a type hint
if get_origin(obj) in (Union, UnionType, Optional):
obj = get_args(obj)
return any(isinstance(o, type) and issubclass(o, tp) for o in obj)
else:
# Other type hint specializations are not supported
return False
return issubclass(obj, tp)
elif isinstance(obj, type):
# common case
return issubclass(obj, tp)

# At this point, `obj` is likely a generic type hint
if (origin := get_origin(obj)) is None:
return False

if origin in (Union, UnionType):
# If we have a Union, try matching any of its args
# (recursively, to handle possibly generic types inside this union)
return any(issubclass_(o, tp) for o in obj.__args__)
else:
return isinstance(origin, type) and issubclass(origin, tp)


def remove_optionals(annotation: Any) -> Any:
Expand Down Expand Up @@ -888,7 +896,6 @@ def isolate_self(
parametersl.pop(0)
if parametersl:
annot = parametersl[0].annotation
annot = get_origin(annot) or annot
if issubclass_(annot, ApplicationCommandInteraction) or annot is inspect.Parameter.empty:
inter_param = parameters.pop(parametersl[0].name)

Expand Down Expand Up @@ -960,9 +967,7 @@ def collect_params(
injections[parameter.name] = default
elif parameter.annotation in Injection._registered:
injections[parameter.name] = Injection._registered[parameter.annotation]
elif issubclass_(
get_origin(parameter.annotation) or parameter.annotation, ApplicationCommandInteraction
):
elif issubclass_(parameter.annotation, ApplicationCommandInteraction):
if inter_param is None:
inter_param = parameter
else:
Expand Down Expand Up @@ -1096,10 +1101,7 @@ def expand_params(command: AnySlashCommand) -> List[Option]:
if param.autocomplete:
command.autocompleters[param.name] = param.autocomplete

if issubclass_(
get_origin(annot := parameters[inter_param].annotation) or annot,
disnake.GuildCommandInteraction,
):
if issubclass_(parameters[inter_param].annotation, disnake.GuildCommandInteraction):
command._guild_only = True

return [param.to_option() for param in params]
Expand Down
22 changes: 11 additions & 11 deletions disnake/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class SystemChannelFlags(BaseFlags, inverted=True):
to enable or disable.
Arguments are applied in order, similar to :class:`Permissions`.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -491,7 +491,7 @@ class MessageFlags(BaseFlags):
See :class:`SystemChannelFlags`.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -681,7 +681,7 @@ def is_voice_message(self):
class PublicUserFlags(BaseFlags):
"""Wraps up the Discord User Public flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -930,7 +930,7 @@ class Intents(BaseFlags):
.. versionadded:: 1.5
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -1617,7 +1617,7 @@ class MemberCacheFlags(BaseFlags):
.. versionadded:: 1.5
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -1793,7 +1793,7 @@ def _voice_only(self):
class ApplicationFlags(BaseFlags):
"""Wraps up the Discord Application flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -1968,7 +1968,7 @@ def application_command_badge(self):
class ChannelFlags(BaseFlags):
"""Wraps up the Discord Channel flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -2081,7 +2081,7 @@ def require_tag(self):
class AutoModKeywordPresets(ListBaseFlags):
"""Wraps up the pre-defined auto moderation keyword lists, provided by Discord.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -2194,7 +2194,7 @@ def slurs(self):
class MemberFlags(BaseFlags):
"""Wraps up Discord Member flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -2296,7 +2296,7 @@ def started_onboarding(self):
class RoleFlags(BaseFlags):
"""Wraps up Discord Role flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down Expand Up @@ -2376,7 +2376,7 @@ def in_prompt(self):
class AttachmentFlags(BaseFlags):
"""Wraps up Discord Attachment flags.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Guild(Hashable):
This is referred to as a "server" in the official Discord UI.
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
2 changes: 1 addition & 1 deletion disnake/guild_scheduled_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class GuildScheduledEvent(Hashable):
.. versionadded:: 2.3
.. container:: operations
.. collapse:: operations
.. describe:: x == y
Expand Down
Loading

0 comments on commit 0bee9dc

Please sign in to comment.