Skip to content

Remove demessaging.types

Philipp Sommer requested to merge remove-types into master

this MR removes the demessaging.types module as we rather move to more explicit configuration options for serializing and validating function parameters. The changes can best be seen in the _test_module_with_xarray.py module, see d88ce7f4

  • demessaging.types.xarray has been removed and split into demessaging.serializers.xarray and demessaging.validators.xarray
  • Instead of using demessaging.types.xarray.DataArray, one is supposed to use the standard xarray.DataArray
Full diff
diff --git a/tests/_test_module_with_xarray.py b/tests/_test_module_with_xarray.py
index dee4d59..52934a8 100644
--- a/tests/_test_module_with_xarray.py
+++ b/tests/_test_module_with_xarray.py
@@ -9,10 +9,11 @@ This module exists just for test purposes
 """
 import uuid
 
-import xarray as xr  # noqa: F401
+import xarray
 
-from demessaging import main
-from demessaging.types.xarray import DataArray
+from demessaging import configure, main
+from demessaging.serializers.xarray import encode_xarray
+from demessaging.validators.xarray import validate_dataarray
 
 __all__ = ["compute_sum"]
 
@@ -20,7 +21,13 @@ __all__ = ["compute_sum"]
 topic = "test_topic_" + uuid.uuid4().urn[9:]
 
 
-def compute_sum(da: DataArray) -> DataArray:
+@configure(
+    serializers={"da": encode_xarray},
+    return_serializer=encode_xarray,
+    validators={"da": [validate_dataarray]},
+    return_validators=[validate_dataarray],
+)
+def compute_sum(da: xarray.DataArray) -> xarray.DataArray:
     """Compute the sum over a data array.
 
     Parameters

Merge request reports

Loading