From 6253c47e37fca4cc2d7f798dfa040c1551e28bb7 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 23 Sep 2024 16:08:56 -0700 Subject: [PATCH] check if video recursion error coming from windows pathing --- src/numpydantic/interface/interface.py | 10 +++++++--- src/numpydantic/serialization.py | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/numpydantic/interface/interface.py b/src/numpydantic/interface/interface.py index 6b1e5a4..d3c9119 100644 --- a/src/numpydantic/interface/interface.py +++ b/src/numpydantic/interface/interface.py @@ -142,7 +142,11 @@ class MarkedJson(BaseModel): Try to cast to MarkedJson if applicable, otherwise return input """ if isinstance(value, dict) and "interface" in value and "value" in value: - value = MarkedJson(**value) + try: + value = MarkedJson(**value) + except ValidationError: + # fine, just not a MarkedJson dict even if it looks like one + return value return value @@ -385,7 +389,7 @@ class Interface(ABC, Generic[T]): """ @classmethod - def mark_json(cls, array: Union[list, dict]) -> MarkedJson: + def mark_json(cls, array: Union[list, dict]) -> dict: """ When using ``model_dump_json`` with ``mark_interface: True`` in the ``context``, add additional annotations that would allow the serialized array to be @@ -402,7 +406,7 @@ class Interface(ABC, Generic[T]): 'version': '1.2.2'}, 'value': [1.0, 2.0]} """ - return MarkedJson.model_construct(interface=cls.mark_interface(), value=array) + return {"interface": cls.mark_interface(), "value": array} @classmethod def interfaces( diff --git a/src/numpydantic/serialization.py b/src/numpydantic/serialization.py index f5c7b35..c60136c 100644 --- a/src/numpydantic/serialization.py +++ b/src/numpydantic/serialization.py @@ -23,13 +23,13 @@ def jsonize_array(value: Any, info: SerializationInfo) -> Union[list, dict]: if info.context: if info.context.get("mark_interface", False): - array = interface_cls.mark_json(array).model_dump() + array = interface_cls.mark_json(array) if info.context.get("absolute_paths", False): array = _absolutize_paths(array) - else: - relative_to = info.context.get("relative_to", ".") - array = _relativize_paths(array, relative_to) + # else: + # relative_to = info.context.get("relative_to", ".") + # array = _relativize_paths(array, relative_to) return array