Repository: hikari-py/hikari
Pull request #1101 (2022-03-25 18:24:24)

Fix locale bugs and regressions
### Summary
Fix some bugs and a regression introduced by https://github.com/hikari-py/hikari/pull/1090.

### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [x] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.



Patch:
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 016446f0..5351df18 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -7,7 +7,7 @@ mock==4.0.3
 
 # Py.test stuff.
 pytest==7.1.1
-pytest-asyncio==0.18.2
+pytest-asyncio==0.18.3
 pytest-cov==3.0.0
 pytest-randomly==3.11.0
 
@@ -28,7 +28,7 @@ sphobjinv==2.2.2
 # TYPE CHECKING #
 #################
 
-mypy==0.941
+mypy==0.942
 pyright==1.1.231
 
 #######################
diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py
index 87813421..628e8c28 100644
--- a/hikari/impl/entity_factory.py
+++ b/hikari/impl/entity_factory.py
@@ -1965,7 +1965,7 @@ def deserialize_command_interaction(
             id=snowflakes.Snowflake(payload["id"]),
             type=base_interactions.InteractionType(payload["type"]),
             guild_id=guild_id,
-            guild_locale=locales.Locale(payload.get("guild_locale", "en-US")),
+            guild_locale=locales.Locale(payload["guild_locale"]) if "guild_locale" in payload else None,
             locale=locales.Locale(payload["locale"]),
             channel_id=snowflakes.Snowflake(payload["channel_id"]),
             member=member,
@@ -2023,7 +2023,7 @@ def deserialize_autocomplete_interaction(
             options=options,
             resolved=resolved,
             locale=locales.Locale(payload["locale"]),
-            guild_locale=locales.Locale(payload.get("guild_locale")),
+            guild_locale=locales.Locale(payload["guild_locale"]) if "guild_locale" in payload else None,
         )
 
     def deserialize_interaction(self, payload: data_binding.JSONObject) -> base_interactions.PartialInteraction:
@@ -2098,7 +2098,7 @@ def deserialize_component_interaction(
             component_type=message_models.ComponentType(data_payload["component_type"]),
             message=self.deserialize_message(payload["message"]),
             locale=locales.Locale(payload["locale"]),
-            guild_locale=locales.Locale(payload.get("guild_locale")),
+            guild_locale=locales.Locale(payload["guild_locale"]) if "guild_locale" in payload else None,
         )
 
     ##################
@@ -2887,7 +2887,7 @@ def deserialize_my_user(self, payload: data_binding.JSONObject) -> user_models.O
             is_bot=user_fields.is_bot,
             is_system=user_fields.is_system,
             is_mfa_enabled=payload["mfa_enabled"],
-            locale=locales.Locale(payload["locale"]),
+            locale=locales.Locale(payload["locale"]) if "locale" in payload else None,
             is_verified=payload.get("verified"),
             email=payload.get("email"),
             flags=user_models.UserFlag(payload["flags"]),
diff --git a/hikari/interactions/command_interactions.py b/hikari/interactions/command_interactions.py
index 01ae6094..53182fa0 100644
--- a/hikari/interactions/command_interactions.py
+++ b/hikari/interactions/command_interactions.py
@@ -171,10 +171,7 @@ class AutocompleteInteractionOption(CommandInteractionOption):
 @attr_extensions.with_copy
 @attr.define(hash=True, kw_only=True, weakref_slot=False)
 class BaseCommandInteraction(base_interactions.PartialInteraction):
-    """Represents a base command interaction on Discord.
-
-    May be a command interaction or an autocomplete interaction.
-    """
+    """Represents a base command interaction on Discord."""
 
     channel_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True)
     """ID of the channel this command interaction event was triggered in."""
diff --git a/hikari/users.py b/hikari/users.py
index f8d9d2ca..92bc21e7 100644
--- a/hikari/users.py
+++ b/hikari/users.py
@@ -758,7 +758,10 @@ class OwnUser(UserImpl):
     """Whether the user's account has multi-factor authentication enabled."""
 
     locale: typing.Optional[typing.Union[str, locales.Locale]] = attr.field(eq=False, hash=False, repr=False)
-    """The user's set language. This is not provided by the `READY` event."""
+    """The user's set locale.
+
+    This is not provided in the `READY` event.
+    """
 
     is_verified: typing.Optional[bool] = attr.field(eq=False, hash=False, repr=False)
     """Whether the email for this user's account has been verified.


Test patch:
diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py
index 564ed32e..95153bad 100644
--- a/tests/hikari/impl/test_entity_factory.py
+++ b/tests/hikari/impl/test_entity_factory.py
@@ -3063,6 +3063,7 @@ def test_deserialize_command_interaction_with_null_attributes(
         command_interaction_payload["user"] = user_payload
         del command_interaction_payload["data"]["resolved"]
         del command_interaction_payload["data"]["options"]
+        del command_interaction_payload["guild_locale"]
 
         interaction = entity_factory_impl.deserialize_command_interaction(command_interaction_payload)
 
@@ -3071,6 +3072,7 @@ def test_deserialize_command_interaction_with_null_attributes(
         assert interaction.user == entity_factory_impl.deserialize_user(user_payload)
         assert interaction.options is None
         assert interaction.resolved is None
+        assert interaction.guild_locale is None
 
     @pytest.fixture()
     def autocomplete_interaction_payload(self, user_payload, interaction_resolved_data_payload):
@@ -3151,35 +3153,20 @@ def test_deserialize_autocomplete_interaction(
 
         assert isinstance(interaction, command_interactions.AutocompleteInteraction)
 
-    def test_deserialize_autocomplete_interaction_with_null_fields(self, entity_factory_impl, user_payload, mock_app):
-        interaction = entity_factory_impl.deserialize_autocomplete_interaction(
-            {
-                "id": "3490190239012093",
-                "type": 4,
-                "data": {
-                    "id": "43123123",
-                    "name": "okokokok",
-                    "type": 1,
-                    "options": [
-                        {"name": "go ice", "type": 6, "value": "115590097100865541"},
-                        {"name": "go fire", "type": 3, "value": "typing...", "focused": True},
-                        {"name": "stuff", "type": 1, "value": {"name": "stuff", "type": 3, "value": "none"}},
-                    ],
-                },
-                "user": user_payload,
-                "channel_id": "49949494",
-                "token": "moe cat girls",
-                "locale": "es-ES",
-                "guild_locale": "en-US",
-                "version": 69420,
-                "application_id": "76234234",
-            }
-        )
+    def test_deserialize_autocomplete_interaction_with_null_fields(
+        self, entity_factory_impl, user_payload, mock_app, autocomplete_interaction_payload
+    ):
+        del autocomplete_interaction_payload["data"]["resolved"]
+        del autocomplete_interaction_payload["guild_locale"]
+        del autocomplete_interaction_payload["guild_id"]
+
+        interaction = entity_factory_impl.deserialize_autocomplete_interaction(autocomplete_interaction_payload)
 
         assert interaction.guild_id is None
         assert interaction.member is None
         assert interaction.user == entity_factory_impl.deserialize_user(user_payload)
         assert interaction.resolved is None
+        assert interaction.guild_locale is None
 
     def test_deserialize_interaction_returns_expected_type(
         self, entity_factory_impl, command_interaction_payload, component_interaction_payload
@@ -5267,7 +5254,6 @@ def test_deserialize_my_user_with_unset_fields(self, entity_factory_impl, mock_a
                 "username": "qt pi",
                 "avatar": "820d0e50543216e812ad94e6ab7",
                 "discriminator": "2880",
-                "locale": "en-US",
                 "mfa_enabled": True,
                 "public_flags": int(user_models.UserFlag.EARLY_VERIFIED_DEVELOPER),
                 "flags": int(user_models.UserFlag.PARTNERED_SERVER_OWNER | user_models.UserFlag.DISCORD_EMPLOYEE),
@@ -5281,6 +5267,7 @@ def test_deserialize_my_user_with_unset_fields(self, entity_factory_impl, mock_a
         assert my_user.is_system is False
         assert my_user.is_verified is None
         assert my_user.email is None
+        assert my_user.locale is None
         assert isinstance(my_user, user_models.OwnUser)
 
     ################