Skip to content

Commit

Permalink
fix: handle optional locales properly (DisnakeDev#533)
Browse files Browse the repository at this point in the history
fixes a regression from DisnakeDevGH-439
  • Loading branch information
shiftinv authored and onerandomusername committed Jul 17, 2022
1 parent 6b02ee7 commit 1aa9390
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions disnake/guild.py
Expand Up @@ -235,7 +235,7 @@ class Guild(Hashable):
The number goes from 0 to 3 inclusive.
premium_subscription_count: :class:`int`
The number of "boosts" this guild currently has.
preferred_locale: Optional[:class:`Locale`]
preferred_locale: :class:`Locale`
The preferred locale for the guild. Used when filtering Server Discovery
results to a specific language.
Expand Down Expand Up @@ -539,7 +539,7 @@ def _from_data(self, guild: GuildPayload) -> None:
self.premium_tier: int = guild.get("premium_tier", 0)
self.premium_subscription_count: int = guild.get("premium_subscription_count") or 0
self._system_channel_flags: int = guild.get("system_channel_flags", 0)
self.preferred_locale: Optional[Locale] = try_enum(Locale, guild.get("preferred_locale"))
self.preferred_locale: Locale = try_enum(Locale, guild.get("preferred_locale"))
self._discovery_splash: Optional[str] = guild.get("discovery_splash")
self._rules_channel_id: Optional[int] = utils._get_as_snowflake(guild, "rules_channel_id")
self._public_updates_channel_id: Optional[int] = utils._get_as_snowflake(
Expand Down
5 changes: 4 additions & 1 deletion disnake/interactions/base.py
Expand Up @@ -191,7 +191,10 @@ def __init__(self, *, data: InteractionPayload, state: ConnectionState):
self.channel_id: int = int(data["channel_id"])
self.guild_id: Optional[int] = utils._get_as_snowflake(data, "guild_id")
self.locale: Locale = try_enum(Locale, data["locale"])
self.guild_locale: Optional[Locale] = try_enum(Locale, data.get("guild_locale"))
guild_locale = data.get("guild_locale")
self.guild_locale: Optional[Locale] = (
try_enum(Locale, guild_locale) if guild_locale else None
)
# one of user and member will always exist
self.author: Union[User, Member] = MISSING
self._permissions = None
Expand Down
4 changes: 2 additions & 2 deletions disnake/user.py
Expand Up @@ -348,9 +348,9 @@ def __repr__(self) -> str:

def _update(self, data: UserPayload) -> None:
super()._update(data)
# There's actually an Optional[str] phone field as well but I won't use it
self.verified = data.get("verified", False)
self.locale = try_enum(Locale, data.get("locale"))
locale = data.get("locale")
self.locale = try_enum(Locale, locale) if locale else None
self._flags = data.get("flags", 0)
self.mfa_enabled = data.get("mfa_enabled", False)

Expand Down

0 comments on commit 1aa9390

Please sign in to comment.