diff --git a/linkml_runtime/utils/metamodelcore.py b/linkml_runtime/utils/metamodelcore.py index d490ee2d..fbadf7df 100644 --- a/linkml_runtime/utils/metamodelcore.py +++ b/linkml_runtime/utils/metamodelcore.py @@ -229,6 +229,7 @@ def __new__(cls, value: Union[str, datetime.time, datetime.datetime, Literal]) - raise ValueError(f"{value} is not a valid time") if isinstance(value, Literal): value = value.value + try: if not isinstance(value, datetime.time): value = datetime.time.fromisoformat(value) @@ -236,8 +237,8 @@ def __new__(cls, value: Union[str, datetime.time, datetime.datetime, Literal]) - except (TypeError, ValueError): if is_strict(): raise - finally: - return str(value) + + return str(value) @classmethod def is_valid(cls, value: Union[str, datetime.time, datetime.datetime, Literal]) -> bool: @@ -260,6 +261,7 @@ def __new__(cls, value: Union[str, datetime.date, Literal]) -> str: raise ValueError(f"{value} is not a valid date") if isinstance(value, Literal): value = value.value + try: if not isinstance(value, datetime.date): value = datetime.date.fromisoformat(str(value)) @@ -267,8 +269,8 @@ def __new__(cls, value: Union[str, datetime.date, Literal]) -> str: except (TypeError, ValueError): if is_strict(): raise - finally: - return str(value) + + return str(value) @classmethod def is_valid(cls, value: Union[str, datetime.date, Literal]) -> bool: @@ -293,6 +295,7 @@ def __new__(cls, value: Union[str, datetime.datetime, Literal]) -> str: raise ValueError(f"{value} is not a valid datetime") if isinstance(value, Literal): value = value.value + try: if not isinstance(value, datetime.datetime): value = datetime.datetime.fromisoformat(value) # Note that this handles non 'T' format as well @@ -300,8 +303,8 @@ def __new__(cls, value: Union[str, datetime.datetime, Literal]) -> str: except (TypeError, ValueError): if is_strict(): raise - finally: - return str(value) + + return str(value) @classmethod def is_valid(cls, value: Union[str, datetime.datetime, Literal]) -> bool: