Repository: PrefectHQ/prefect

Issue:
Remove src/prefect/serializers.py
I think the work @cicdw has done in #389 removes the need for this file


Discussion:

Resolving patch:
diff --git a/src/prefect/serializers.py b/src/prefect/serializers.py
deleted file mode 100644
--- a/src/prefect/serializers.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# Licensed under LICENSE.md; also available at https://www.prefect.io/licenses/alpha-eula
-
-"""
-Parent classes which are used to build custom functionality to allow serializable
-objects in the prefect library.
-"""
-
-from typing import Any
-
-import json
-
-
-class Serializer:
-    """
-    Parent implementation of a class in which objects can be serialized and deserialized.
-    """
-
-    @classmethod
-    def serialize(cls, object: Any) -> str:
-        """
-        Serialize provided object.
-
-        Args:
-            - object (Any): object to serialize
-
-        Returns:
-            - str: serialized object
-
-        Raises:
-            - NotImplementedError: if this method hasn't been implemented in the child class
-        """
-        raise NotImplementedError()
-
-    @classmethod
-    def deserialize(cls, key: str) -> Any:
-        """
-        Deserialize provided key.
-
-        Args:
-            - key (str): serialized key to deserialize
-
-        Returns:
-            - Any: deserialized object
-
-        Raises:
-            - NotImplementedError: if this method hasn't been implemented in the child class
-        """
-        raise NotImplementedError()
-
-
-class JSONSerializer:
-    @classmethod
-    def serialize(cls, object: Any) -> str:
-        """
-        Serializes an object
-
-        Args:
-            - object (Any): an object to be dumped to a json string
-
-        Returns:
-            - str: An encoded json string
-        """
-        return json.dumps(object)
-
-    @classmethod
-    def deserialize(cls, key: str) -> Any:
-        """
-        Deserializes an encoded json string
-
-        Args:
-            - key (str): a json string to be loaded
-
-        Returns:
-            - A decoded json string in the form of the original object before serialization
-        """
-        return json.loads(key)
diff --git a/src/prefect/tasks/serialize.py b/src/prefect/tasks/serialize.py
deleted file mode 100644
--- a/src/prefect/tasks/serialize.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Licensed under LICENSE.md; also available at https://www.prefect.io/licenses/alpha-eula
-
-from typing import Any
-
-from prefect import Task
-from prefect.serializers import Serializer
-
-
-class SerializeTask(Task):
-    """
-    Serialize a result using a serializer. The serialized result must be less than 1kb.
-
-    Args:
-        - serializer (prefect.serializers.Seralizer): serializer to use
-        - *args: additional args to pass to `Task` initialization
-        - *kwargs: additional kwargs to pass to `Task` initialization
-    """
-
-    def __init__(self, serializer: Serializer, *args: Any, **kwargs: Any) -> None:
-        self.serializer = serializer
-        super().__init__(*args, **kwargs)
-
-    def run(self, data: Any) -> str:  # type: ignore
-        """
-        Serializes provided data using `self.serialize`
-
-        Args:
-            - data (Any): data to serialize
-
-        Returns:
-            - str: serialized data
-        """
-        serialized = self.serializer.serialize(data)
-        if not isinstance(serialized, str):
-            raise TypeError(
-                "Serialized value must be a string; received {}".format(
-                    type(serialized)
-                )
-            )
-        elif len(serialized.encode("utf-8")) > 1024:
-            raise ValueError("Serialized values must be less than 1kb")
-        return serialized
-
-
-class DeserializeTask(Task):
-    """
-    Deserialize a result from a serialized value.
-
-    Args:
-        - serializer (prefect.serializers.Seralizer): serializer to use
-        - *args: additional args to pass to `Task` initialization
-        - *kwargs: additional kwargs to pass to `Task` initialization
-    """
-
-    def __init__(self, serializer: Serializer, *args: Any, **kwargs: Any) -> None:
-        self.serializer = serializer
-        super().__init__(*args, **kwargs)
-
-    def run(self, serialized: str) -> Any:  # type: ignore
-        """
-        Deserializes provided data using `self.serialize`
-
-        Args:
-            - data (str): data to serialize
-
-        Returns:
-            - deserialized data
-        """
-        return self.serializer.deserialize(serialized)


Test patch:
diff --git a/tests/test_serializers.py b/tests/test_serializers.py
deleted file mode 100644
--- a/tests/test_serializers.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import datetime
-
-import prefect.serializers as serializers
-import json
-
-
-def test_JSONSerializer_on_simple_string():
-    s = serializers.JSONSerializer
-    x = "x"
-    j = s.serialize(x)
-    assert j == '"x"'
-    assert s.deserialize(j) == x
-
-
-def test_JSONSerializer_on_dict():
-    s = serializers.JSONSerializer
-    x = {"1": "a", "b": [2, {"3": 4}]}
-    j = s.serialize(x)
-    assert json.loads(j) == x
-    assert s.deserialize(j) == x