Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle optional locales properly #533

Merged
merged 1 commit into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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