Repository: PrefectHQ/prefect

Issue:
PIN 16: Implement `Result` subtype mimicking `ConstantResultHandler`
## Use Case
See PIN 16 (PR #2134) for background. This is a spin-off from #2141 for only one (special) handler, `ConstantResultHandler`, which has internal implications.

## Solution
Implement a `Result` subclass for `ConstantResultHandler` that knows how to `.read`, `write`, and check if it `.exists` and operates properly for the same internal purposes as the current `ConstantResultHandler` does.

## Alternatives
*Please describe any alternatives you've considered, even if you've dismissed them*



Discussion:

Resolving patch:
diff --git a/src/prefect/engine/results/__init__.py b/src/prefect/engine/results/__init__.py
new file mode 100644
--- /dev/null
+++ b/src/prefect/engine/results/__init__.py
@@ -0,0 +1 @@
+from prefect.engine.results.constant_result import ConstantResult
diff --git a/src/prefect/engine/results/constant_result.py b/src/prefect/engine/results/constant_result.py
new file mode 100644
--- /dev/null
+++ b/src/prefect/engine/results/constant_result.py
@@ -0,0 +1,48 @@
+from typing import Any, Optional
+
+from prefect.engine.result import Result
+
+
+class ConstantResult(Result):
+    """
+    Hook for storing and retrieving constant Python objects. Only intended to be used
+    internally.
+
+    Args:
+        - value (Any): the underlying value this Result should represent
+    """
+
+    def __init__(self, value: Any = None, **kwargs: Any) -> None:
+        self.value = value
+        super().__init__(value=value, **kwargs)
+
+    def read(self, arg: Optional[str] = None) -> Any:
+        """
+        Returns the underlying value regardless of the argument passed.
+
+        Args:
+            - arg (str): an unused argument
+        """
+        return self.value
+
+    def write(self) -> str:
+        """
+        Returns the repr of the underlying value, purely for convenience.
+
+        Returns:
+            - str: the repr of the result
+        """
+        return repr(self.value)
+
+    def exists(self) -> bool:
+        """
+        Confirms the existence of the Constant value stored in the Result.
+
+        The value stored within a Constant is logically always present,
+        so `True` is returned.
+
+        Returns:
+            - bool: True, confirming the constant exists.
+        """
+
+        return True


Test patch:
diff --git a/tests/engine/result_handlers/test_result_handlers.py b/tests/engine/result_handlers/test_result_handlers.py
--- a/tests/engine/result_handlers/test_result_handlers.py
+++ b/tests/engine/result_handlers/test_result_handlers.py
@@ -17,10 +17,44 @@
     ResultHandler,
     S3ResultHandler,
     SecretResultHandler,
+    ConstantResultHandler,
 )
 from prefect.utilities.configuration import set_temporary_config
 
 
+class TestConstantResultHandler:
+    def test_instantiates_with_value(self):
+        handler = ConstantResultHandler(5)
+        assert handler.value == 5
+
+        handler = ConstantResultHandler(value=10)
+        assert handler.value == 10
+
+    def test_read_returns_value(self):
+        handler = ConstantResultHandler("hello world")
+        assert handler.read("this param isn't used") == "hello world"
+
+    def test_write_doesnt_overwrite_value(self):
+        handler = ConstantResultHandler("untouchable!")
+
+        handler.write("a different value")
+        assert handler.value == "untouchable!"
+        assert handler.read("still unused") == "untouchable!"
+
+    def test_write_returns_value(self):
+        handler = ConstantResultHandler("constant value")
+
+        output = handler.write("a different value")
+        assert output == "'constant value'"
+
+    def test_handles_none_as_constant(self):
+
+        handler = ConstantResultHandler(None)
+        assert handler.read("still not used") is None
+        output = handler.write("also not used")
+        assert output == "None"
+
+
 class TestJSONHandler:
     def test_json_handler_initializes_with_no_args(self):
         handler = JSONResultHandler()
diff --git a/tests/engine/results/__init__.py b/tests/engine/results/__init__.py
new file mode 100644
diff --git a/tests/engine/results/test_results.py b/tests/engine/results/test_results.py
new file mode 100644
--- /dev/null
+++ b/tests/engine/results/test_results.py
@@ -0,0 +1,49 @@
+from typing import Union
+
+import pytest
+
+from prefect.engine.results import ConstantResult
+from prefect.tasks.core.constants import Constant
+
+
+class TestConstantResult:
+    def test_instantiates_with_value(self):
+        constant_result = ConstantResult(5)
+        assert constant_result.value == 5
+
+        constant_result = ConstantResult(value=10)
+        assert constant_result.value == 10
+
+    def test_read_returns_value(self):
+        constant_result = ConstantResult("hello world")
+        assert constant_result.read("this param isn't used") == "hello world"
+
+    def test_write_doesnt_overwrite_value(self):
+        constant_result = ConstantResult("untouchable!")
+
+        constant_result.write()
+        assert constant_result.value == "untouchable!"
+        assert constant_result.read("still unused") == "untouchable!"
+
+    def test_write_returns_value(self):
+        constant_result = ConstantResult("constant value")
+
+        output = constant_result.write()
+        assert output == "'constant value'"
+
+    def test_handles_none_as_constant(self):
+
+        constant_result = ConstantResult(None)
+        assert constant_result.read("still not used") is None
+        output = constant_result.write()
+        assert output == "None"
+
+    @pytest.mark.parametrize(
+        "constant_value", [3, "text", 5.0, Constant(3), Constant("text"), Constant(5.0)]
+    )
+    def test_exists(self, constant_value: Union[str, Constant]):
+
+        result = ConstantResult(constant_value)
+        result_exists = result.exists()
+
+        assert result_exists is True