Repository: hikari-py/hikari
Pull request #1074 (2022-03-12 12:40:29)

Hide the component deserialize methods on the entity factory
### Summary
These shouldn't have ever been exposed as they're only ever used within the entity factory

### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [ ] I have run `nox` and all the pipelines have passed.
- [ ] I have made unittests according to the code I have added/modified/deleted.

### Related issues
<!--
To mention an issue use `#issue-id` and to mention a merge request use `!merge-request-id`
To close/fix an issue use `Close #issue-id` or `Fix #issue-id` (depending on the merge request)
-->



Patch:
diff --git a/changes/1074.breaking.md b/changes/1074.breaking.md
new file mode 100644
index 00000000..c8be934b
--- /dev/null
+++ b/changes/1074.breaking.md
@@ -0,0 +1,1 @@
+Hide the entity factory's component deserialize methods.
diff --git a/hikari/api/entity_factory.py b/hikari/api/entity_factory.py
index 3f2688e2..8d127524 100644
--- a/hikari/api/entity_factory.py
+++ b/hikari/api/entity_factory.py
@@ -1296,68 +1296,6 @@ def deserialize_guild_sticker(self, payload: data_binding.JSONObject) -> sticker
     # MESSAGE MODELS #
     ##################
 
-    @abc.abstractmethod
-    def deserialize_action_row(self, payload: data_binding.JSONObject) -> message_models.ActionRowComponent:
-        """Parse a raw payload from Discord into an action row component object.
-
-        Parameters
-        ----------
-        payload : hikari.internal.data_binding.JSONObject
-            The JSON payload to deserialize.
-
-        Returns
-        -------
-        hikari.messages.ActionRowComponent
-            The deserialized action row component.
-        """
-
-    @abc.abstractmethod
-    def deserialize_button(self, payload: data_binding.JSONObject) -> message_models.ButtonComponent:
-        """Parse a raw payload from Discord into a button component object.
-
-        Parameters
-        ----------
-        payload : hikari.internal.data_binding.JSONObject
-            The JSON payload to deserialize.
-
-        Returns
-        -------
-        hikari.messages.ButtonComponent
-            The deserialized button component.
-        """
-
-    @abc.abstractmethod
-    def deserialize_select_menu(self, payload: data_binding.JSONObject) -> message_models.SelectMenuComponent:
-        """Parse a raw payload from Discord into a select menu component object.
-
-        Parameters
-        ----------
-        payload : hikari.internal.data_binding.JSONObject
-            The JSON payload to deserialize.
-
-        Returns
-        -------
-        hikari.messages.SelectMenuComponent
-            The deserialized button component.
-        """
-
-    @abc.abstractmethod
-    def deserialize_component(self, payload: data_binding.JSONObject) -> message_models.PartialComponent:
-        """Parse a raw payload from Discord into a message component object.
-
-        Parameters
-        ----------
-        payload : hikari.internal.data_binding.JSONObject
-            The JSON payload to deserialize.
-
-        Returns
-        -------
-        hikari.messages.PartialComponent
-            The deserialized message component.
-        hikari.errors.UnrecognisedEntityError
-            If the message component type isn't recognised.
-        """
-
     @abc.abstractmethod
     def deserialize_partial_message(self, payload: data_binding.JSONObject) -> message_models.PartialMessage:
         """Parse a raw payload from Discord into a partial message object.
diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py
index 5f1dfb30..45ad579e 100644
--- a/hikari/impl/entity_factory.py
+++ b/hikari/impl/entity_factory.py
@@ -261,9 +261,9 @@ def __init__(self, app: traits.RESTAware) -> None:
             commands.CommandType.MESSAGE: self.deserialize_context_menu_command,
         }
         self._component_type_mapping = {
-            message_models.ComponentType.ACTION_ROW: self.deserialize_action_row,
-            message_models.ComponentType.BUTTON: self.deserialize_button,
-            message_models.ComponentType.SELECT_MENU: self.deserialize_select_menu,
+            message_models.ComponentType.ACTION_ROW: self._deserialize_action_row,
+            message_models.ComponentType.BUTTON: self._deserialize_button,
+            message_models.ComponentType.SELECT_MENU: self._deserialize_select_menu,
         }
         self._dm_channel_type_mapping = {
             channel_models.ChannelType.DM: self.deserialize_dm,
@@ -2181,12 +2181,12 @@ def deserialize_guild_sticker(self, payload: data_binding.JSONObject) -> sticker
     # MESSAGE MODELS #
     ##################
 
-    def deserialize_action_row(self, payload: data_binding.JSONObject) -> message_models.ActionRowComponent:
+    def _deserialize_action_row(self, payload: data_binding.JSONObject) -> message_models.ActionRowComponent:
         components: typing.List[message_models.PartialComponent] = []
 
         for component_payload in payload["components"]:
             try:
-                components.append(self.deserialize_component(component_payload))
+                components.append(self._deserialize_component(component_payload))
 
             except errors.UnrecognisedEntityError:
                 pass
@@ -2195,7 +2195,7 @@ def deserialize_action_row(self, payload: data_binding.JSONObject) -> message_mo
             type=message_models.ComponentType(payload["type"]), components=components
         )
 
-    def deserialize_button(self, payload: data_binding.JSONObject) -> message_models.ButtonComponent:
+    def _deserialize_button(self, payload: data_binding.JSONObject) -> message_models.ButtonComponent:
         emoji_payload = payload.get("emoji")
         return message_models.ButtonComponent(
             type=message_models.ComponentType(payload["type"]),
@@ -2207,7 +2207,7 @@ def deserialize_button(self, payload: data_binding.JSONObject) -> message_models
             is_disabled=payload.get("disabled", False),
         )
 
-    def deserialize_select_menu(self, payload: data_binding.JSONObject) -> message_models.SelectMenuComponent:
+    def _deserialize_select_menu(self, payload: data_binding.JSONObject) -> message_models.SelectMenuComponent:
         options: typing.List[message_models.SelectMenuOption] = []
         for option_payload in payload["options"]:
             emoji = None
@@ -2234,7 +2234,7 @@ def deserialize_select_menu(self, payload: data_binding.JSONObject) -> message_m
             is_disabled=payload.get("disabled", False),
         )
 
-    def deserialize_component(self, payload: data_binding.JSONObject) -> message_models.PartialComponent:
+    def _deserialize_component(self, payload: data_binding.JSONObject) -> message_models.PartialComponent:
         component_type = message_models.ComponentType(payload["type"])
 
         if deserialize := self._component_type_mapping.get(component_type):
@@ -2390,7 +2390,7 @@ def deserialize_partial_message(  # noqa CFQ001 - Function too long
             components = []
             for component_payload in component_payloads:
                 try:
-                    components.append(self.deserialize_component(component_payload))
+                    components.append(self._deserialize_component(component_payload))
 
                 except errors.UnrecognisedEntityError:
                     pass
@@ -2509,7 +2509,7 @@ def deserialize_message(
         if component_payloads := payload.get("components"):
             for component_payload in component_payloads:
                 try:
-                    components.append(self.deserialize_component(component_payload))
+                    components.append(self._deserialize_component(component_payload))
 
                 except errors.UnrecognisedEntityError:
                     pass


Test patch:
diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py
index 36158647..404df0fe 100644
--- a/tests/hikari/impl/test_entity_factory.py
+++ b/tests/hikari/impl/test_entity_factory.py
@@ -3939,14 +3939,14 @@ def test_max_age_when_zero(self, entity_factory_impl, invite_with_metadata_paylo
     def action_row_payload(self, button_payload):
         return {"type": 1, "components": [button_payload]}
 
-    def test_deserialize_action_row(self, entity_factory_impl, action_row_payload, button_payload):
-        action_row = entity_factory_impl.deserialize_action_row(action_row_payload)
+    def test__deserialize_action_row(self, entity_factory_impl, action_row_payload, button_payload):
+        action_row = entity_factory_impl._deserialize_action_row(action_row_payload)
 
         assert action_row.type is message_models.ComponentType.ACTION_ROW
-        assert action_row.components == [entity_factory_impl.deserialize_component(button_payload)]
+        assert action_row.components == [entity_factory_impl._deserialize_component(button_payload)]
 
-    def test_deserialize_action_row_handles_unknown_component_type(self, entity_factory_impl):
-        action_row = entity_factory_impl.deserialize_action_row(
+    def test__deserialize_action_row_handles_unknown_component_type(self, entity_factory_impl):
+        action_row = entity_factory_impl._deserialize_action_row(
             {"type": 1, "components": [{"type": "9494949"}, {"type": "9239292"}]}
         )
 
@@ -3964,8 +3964,8 @@ def button_payload(self, custom_emoji_payload):
             "disabled": True,
         }
 
-    def test_deserialize_deserialize_button(self, entity_factory_impl, button_payload, custom_emoji_payload):
-        button = entity_factory_impl.deserialize_button(button_payload)
+    def test_deserialize__deserialize_button(self, entity_factory_impl, button_payload, custom_emoji_payload):
+        button = entity_factory_impl._deserialize_button(button_payload)
 
         assert button.type is message_models.ComponentType.BUTTON
         assert button.style is message_models.ButtonStyle.PRIMARY
@@ -3975,10 +3975,10 @@ def test_deserialize_deserialize_button(self, entity_factory_impl, button_payloa
         assert button.is_disabled is True
         assert button.url == "okokok"
 
-    def test_deserialize_deserialize_button_with_unset_fields(
+    def test_deserialize__deserialize_button_with_unset_fields(
         self, entity_factory_impl, button_payload, custom_emoji_payload
     ):
-        button = entity_factory_impl.deserialize_button({"type": 2, "style": 5})
+        button = entity_factory_impl._deserialize_button({"type": 2, "style": 5})
 
         assert button.type is message_models.ComponentType.BUTTON
         assert button.style is message_models.ButtonStyle.LINK
@@ -4008,8 +4008,8 @@ def select_menu_payload(self, custom_emoji_payload):
             "disabled": True,
         }
 
-    def test_deserialize_select_menu(self, entity_factory_impl, select_menu_payload, custom_emoji_payload):
-        menu = entity_factory_impl.deserialize_select_menu(select_menu_payload)
+    def test__deserialize_select_menu(self, entity_factory_impl, select_menu_payload, custom_emoji_payload):
+        menu = entity_factory_impl._deserialize_select_menu(select_menu_payload)
 
         assert menu.type is message_models.ComponentType.SELECT_MENU
         assert menu.custom_id == "Not an ID"
@@ -4029,8 +4029,8 @@ def test_deserialize_select_menu(self, entity_factory_impl, select_menu_payload,
         assert menu.max_values == 420
         assert menu.is_disabled is True
 
-    def test_deserialize_select_menu_partial(self, entity_factory_impl):
-        menu = entity_factory_impl.deserialize_select_menu(
+    def test__deserialize_select_menu_partial(self, entity_factory_impl):
+        menu = entity_factory_impl._deserialize_select_menu(
             {
                 "type": 3,
                 "custom_id": "Not an ID",
@@ -4050,17 +4050,17 @@ def test_deserialize_select_menu_partial(self, entity_factory_impl):
         assert menu.max_values == 1
         assert menu.is_disabled is False
 
-    def test_deserialize_component(self, entity_factory_impl, action_row_payload, button_payload, select_menu_payload):
+    def test__deserialize_component(self, entity_factory_impl, action_row_payload, button_payload, select_menu_payload):
         for expected_type, payload in [
             (message_models.ActionRowComponent, action_row_payload),
             (message_models.ButtonComponent, button_payload),
             (message_models.SelectMenuComponent, select_menu_payload),
         ]:
-            assert type(entity_factory_impl.deserialize_component(payload)) is expected_type
+            assert type(entity_factory_impl._deserialize_component(payload)) is expected_type
 
-    def test_deserialize_component_handles_unknown_type(self, entity_factory_impl):
+    def test__deserialize_component_handles_unknown_type(self, entity_factory_impl):
         with pytest.raises(errors.UnrecognisedEntityError):
-            entity_factory_impl.deserialize_component({"type": -9434994})
+            entity_factory_impl._deserialize_component({"type": -9434994})
 
     @pytest.fixture()
     def partial_application_payload(self):
@@ -4300,7 +4300,7 @@ def test_deserialize_partial_message(
         assert partial_message.interaction.user == entity_factory_impl.deserialize_user(user_payload)
         assert isinstance(partial_message.interaction, message_models.MessageInteraction)
 
-        assert partial_message.components == [entity_factory_impl.deserialize_component(action_row_payload)]
+        assert partial_message.components == [entity_factory_impl._deserialize_component(action_row_payload)]
 
     def test_deserialize_partial_message_with_partial_fields(self, entity_factory_impl, message_payload):
         message_payload["content"] = ""
@@ -4482,7 +4482,7 @@ def test_deserialize_message(
         assert message.interaction.user == entity_factory_impl.deserialize_user(user_payload)
         assert isinstance(message.interaction, message_models.MessageInteraction)
 
-        assert message.components == [entity_factory_impl.deserialize_component(action_row_payload)]
+        assert message.components == [entity_factory_impl._deserialize_component(action_row_payload)]
 
     def test_deserialize_message_with_unset_sub_fields(self, entity_factory_impl, message_payload):
         del message_payload["application"]["cover_image"]