f" Please convert the value to string an add a unit - {list(type(self)._units.keys())}",
object_path,
)
- elif isinstance(source_value, type(self)):
- self._value_orig = source_value._value_orig
- self._value = source_value._value
else:
raise DataValidationException(
f"Unexpected input type for Unit type - {type(source_value)}."
class AnyPath(CustomValueType):
def __init__(self, source_value: Any, object_path: str = "/") -> None:
super().__init__(source_value)
- if isinstance(source_value, AnyPath):
- self._value = source_value._value
- elif isinstance(source_value, str):
+ if isinstance(source_value, str):
self._value: Path = Path(source_value)
else:
raise DataValidationException(
# CustomValueType subclasses
elif inspect.isclass(cls) and issubclass(cls, CustomValueType):
- # no validation performed, the implementation does it in the constuctor
- return cls(obj, object_path=object_path)
+ if isinstance(obj, cls):
+ # if we already have a custom value type, just pass it through
+ return obj
+ else:
+ # no validation performed, the implementation does it in the constuctor
+ return cls(obj, object_path=object_path)
# nested DataParser subclasses
elif inspect.isclass(cls) and issubclass(cls, DataParser):