Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/webhook-f…
Browse files Browse the repository at this point in the history
…orum-tags
  • Loading branch information
shiftinv committed Jan 2, 2024
2 parents 8a0344a + f780cf5 commit 585753d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog/1133.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Fix erroneous :class:`LocalizationWarning`\s when using localized slash command parameters in cogs.
1 change: 1 addition & 0 deletions changelog/1134.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :class:`StandardSticker` to ``stickers`` parameter type annotation of :meth:`Messageable.send` and :meth:`ForumChannel.create_thread`.
14 changes: 7 additions & 7 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from .partial_emoji import PartialEmoji
from .permissions import PermissionOverwrite, Permissions
from .role import Role
from .sticker import GuildSticker, StickerItem
from .sticker import GuildSticker, StandardSticker, StickerItem
from .ui.action_row import components_to_dict
from .utils import _overload_with_permissions
from .voice_client import VoiceClient, VoiceProtocol
Expand Down Expand Up @@ -1429,7 +1429,7 @@ async def send(
tts: bool = ...,
embed: Embed = ...,
file: File = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
suppress_embeds: bool = ...,
Expand All @@ -1450,7 +1450,7 @@ async def send(
tts: bool = ...,
embed: Embed = ...,
files: List[File] = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
suppress_embeds: bool = ...,
Expand All @@ -1471,7 +1471,7 @@ async def send(
tts: bool = ...,
embeds: List[Embed] = ...,
file: File = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
suppress_embeds: bool = ...,
Expand All @@ -1492,7 +1492,7 @@ async def send(
tts: bool = ...,
embeds: List[Embed] = ...,
files: List[File] = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
suppress_embeds: bool = ...,
Expand All @@ -1514,7 +1514,7 @@ async def send(
embeds: Optional[List[Embed]] = None,
file: Optional[File] = None,
files: Optional[List[File]] = None,
stickers: Optional[Sequence[Union[GuildSticker, StickerItem]]] = None,
stickers: Optional[Sequence[Union[GuildSticker, StandardSticker, StickerItem]]] = None,
delete_after: Optional[float] = None,
nonce: Optional[Union[str, int]] = None,
suppress_embeds: Optional[bool] = None,
Expand Down Expand Up @@ -1567,7 +1567,7 @@ async def send(
files: List[:class:`.File`]
A list of files to upload. Must be a maximum of 10.
This cannot be mixed with the ``file`` parameter.
stickers: Sequence[Union[:class:`.GuildSticker`, :class:`.StickerItem`]]
stickers: Sequence[Union[:class:`.GuildSticker`, :class:`.StandardSticker`, :class:`.StickerItem`]]
A list of stickers to upload. Must be a maximum of 3.
.. versionadded:: 2.0
Expand Down
14 changes: 7 additions & 7 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
from .message import AllowedMentions, Message, PartialMessage
from .role import Role
from .state import ConnectionState
from .sticker import GuildSticker, StickerItem
from .sticker import GuildSticker, StandardSticker, StickerItem
from .threads import AnyThreadArchiveDuration, ThreadType
from .types.channel import (
CategoryChannel as CategoryChannelPayload,
Expand Down Expand Up @@ -3791,7 +3791,7 @@ async def create_thread(
file: File = ...,
suppress_embeds: bool = ...,
flags: MessageFlags = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
Expand All @@ -3812,7 +3812,7 @@ async def create_thread(
files: List[File] = ...,
suppress_embeds: bool = ...,
flags: MessageFlags = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
Expand All @@ -3833,7 +3833,7 @@ async def create_thread(
file: File = ...,
suppress_embeds: bool = ...,
flags: MessageFlags = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
Expand All @@ -3854,7 +3854,7 @@ async def create_thread(
files: List[File] = ...,
suppress_embeds: bool = ...,
flags: MessageFlags = ...,
stickers: Sequence[Union[GuildSticker, StickerItem]] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
Expand All @@ -3876,7 +3876,7 @@ async def create_thread(
files: List[File] = MISSING,
suppress_embeds: bool = MISSING,
flags: MessageFlags = MISSING,
stickers: Sequence[Union[GuildSticker, StickerItem]] = MISSING,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING,
allowed_mentions: AllowedMentions = MISSING,
view: View = MISSING,
components: Components[MessageUIComponent] = MISSING,
Expand Down Expand Up @@ -3940,7 +3940,7 @@ async def create_thread(
files: List[:class:`.File`]
A list of files to upload. Must be a maximum of 10.
This cannot be mixed with the ``file`` parameter.
stickers: Sequence[Union[:class:`.GuildSticker`, :class:`.StickerItem`]]
stickers: Sequence[Union[:class:`.GuildSticker`, :class:`.StandardSticker`, :class:`.StickerItem`]]
A list of stickers to upload. Must be a maximum of 3.
allowed_mentions: :class:`.AllowedMentions`
Controls the mentions being processed in this message. If this is
Expand Down
7 changes: 6 additions & 1 deletion disnake/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,20 @@ def _copy(self) -> LocalizationValue:
def data(self) -> Optional[Dict[str, str]]:
"""Optional[Dict[:class:`str`, :class:`str`]]: A dict with a locale -> localization mapping, if available."""
if self._data is MISSING:
# This will happen when `_link(store)` hasn't been called yet, which *shouldn't* occur under normal circumstances.
warnings.warn(
f"value ('{self._key}') was never localized, this is likely a library bug",
f"Localization value ('{self._key}') was never linked to bot; this may be a library bug.",
LocalizationWarning,
stacklevel=2,
)
return None
return self._data

def __eq__(self, other) -> bool:
# if both are pending, compare keys instead
if self._data is MISSING and other._data is MISSING:
return self._key == other._key

d1 = self.data
d2 = other.data
# consider values equal if they're both falsy, or actually equal
Expand Down
6 changes: 3 additions & 3 deletions disnake/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from ..mentions import AllowedMentions
from ..message import Attachment
from ..state import ConnectionState
from ..sticker import GuildSticker, StickerItem
from ..sticker import GuildSticker, StandardSticker, StickerItem
from ..types.message import Message as MessagePayload
from ..types.webhook import Webhook as WebhookPayload
from ..ui.action_row import Components
Expand Down Expand Up @@ -491,7 +491,7 @@ def handle_message_parameters_dict(
components: Optional[Components[MessageUIComponent]] = MISSING,
allowed_mentions: Optional[AllowedMentions] = MISSING,
previous_allowed_mentions: Optional[AllowedMentions] = None,
stickers: Sequence[Union[GuildSticker, StickerItem]] = MISSING,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING,
# these parameters are exclusive to webhooks in forum channels
thread_name: str = MISSING,
applied_tags: Sequence[Snowflake] = MISSING,
Expand Down Expand Up @@ -582,7 +582,7 @@ def handle_message_parameters(
components: Optional[Components[MessageUIComponent]] = MISSING,
allowed_mentions: Optional[AllowedMentions] = MISSING,
previous_allowed_mentions: Optional[AllowedMentions] = None,
stickers: Sequence[Union[GuildSticker, StickerItem]] = MISSING,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING,
# these parameters are exclusive to webhooks in forum channels
thread_name: str = MISSING,
applied_tags: Sequence[Snowflake] = MISSING,
Expand Down
18 changes: 18 additions & 0 deletions tests/ext/commands/test_base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import disnake
from disnake import Permissions
from disnake.ext import commands

Expand Down Expand Up @@ -82,3 +83,20 @@ async def overwrite_decorator_below(self, _) -> None:

assert Cog.overwrite_decorator_below.default_member_permissions == Permissions(64)
assert Cog().overwrite_decorator_below.default_member_permissions == Permissions(64)


def test_localization_copy() -> None:
class Cog(commands.Cog):
@commands.slash_command()
async def cmd(
self,
inter,
param: int = commands.Param(name=disnake.Localized("param", key="PARAM")),
) -> None:
...

# Ensure the command copy that happens on cog init doesn't raise a LocalizationWarning for the options.
cog = Cog()

with pytest.warns(disnake.LocalizationWarning):
assert cog.get_slash_commands()[0].options[0].name_localizations.data is None

0 comments on commit 585753d

Please sign in to comment.