From 3c6281ce332a323b5d41af789d11ab342abfc313 Mon Sep 17 00:00:00 2001 From: Sebastian Law Date: Mon, 21 Feb 2022 03:25:23 -0800 Subject: [PATCH] Set attributes of StickerPack as Optional --- discord/sticker.py | 16 ++++++++-------- discord/types/sticker.py | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/discord/sticker.py b/discord/sticker.py index 933b9f425..943e5cb05 100644 --- a/discord/sticker.py +++ b/discord/sticker.py @@ -28,7 +28,7 @@ import unicodedata from .mixins import Hashable from .asset import Asset, AssetMixin -from .utils import cached_slot_property, find, snowflake_time, get, MISSING +from .utils import cached_slot_property, find, snowflake_time, get, MISSING, _get_as_snowflake from .errors import InvalidData from .enums import StickerType, StickerFormatType, try_enum @@ -87,9 +87,9 @@ class StickerPack(Hashable): The stickers of this sticker pack. sku_id: :class:`int` The SKU ID of the sticker pack. - cover_sticker_id: :class:`int` + cover_sticker_id: Optional[:class:`int`] The ID of the sticker used for the cover of the sticker pack. - cover_sticker: :class:`StandardSticker` + cover_sticker: Optional[:class:`StandardSticker`] The sticker used for the cover of the sticker pack. """ @@ -115,15 +115,15 @@ class StickerPack(Hashable): self.stickers: List[StandardSticker] = [StandardSticker(state=self._state, data=sticker) for sticker in stickers] self.name: str = data['name'] self.sku_id: int = int(data['sku_id']) - self.cover_sticker_id: int = int(data['cover_sticker_id']) - self.cover_sticker: StandardSticker = get(self.stickers, id=self.cover_sticker_id) # type: ignore + self.cover_sticker_id: Optional[int] = _get_as_snowflake(data, 'cover_sticker_id') + self.cover_sticker: Optional[StandardSticker] = get(self.stickers, id=self.cover_sticker_id) self.description: str = data['description'] - self._banner: int = int(data['banner_asset_id']) + self._banner: Optional[int] = _get_as_snowflake(data, 'banner_asset_id') @property - def banner(self) -> Asset: + def banner(self) -> Optional[Asset]: """:class:`Asset`: The banner asset of the sticker pack.""" - return Asset._from_sticker_banner(self._state, self._banner) + return self._banner and Asset._from_sticker_banner(self._state, self._banner) def __repr__(self) -> str: return f'' diff --git a/discord/types/sticker.py b/discord/types/sticker.py index ec6922a8c..ab499687f 100644 --- a/discord/types/sticker.py +++ b/discord/types/sticker.py @@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE. from __future__ import annotations -from typing import List, Literal, TypedDict, Union +from typing import List, Literal, TypedDict, Union, Optional from .snowflake import Snowflake from .user import User @@ -69,9 +69,9 @@ class StickerPack(TypedDict): stickers: List[StandardSticker] name: str sku_id: Snowflake - cover_sticker_id: Snowflake + cover_sticker_id: Optional[Snowflake] description: str - banner_asset_id: Snowflake + banner_asset_id: Optional[Snowflake] class _CreateGuildStickerOptional(TypedDict, total=False):