From 6f928091c48cfcbac67e9cf1a2f14a9886c12319 Mon Sep 17 00:00:00 2001 From: Sveinung Gundersen Date: Mon, 2 Sep 2024 11:42:31 +0200 Subject: [PATCH] Amend frozen --- src/omnipy/data/model.py | 5 +++-- src/omnipy/modules/general/models.py | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/omnipy/data/model.py b/src/omnipy/data/model.py index 0f36c494..a0b8627a 100644 --- a/src/omnipy/data/model.py +++ b/src/omnipy/data/model.py @@ -869,8 +869,9 @@ def _parse_with_root_type_if_model(cls, return cast(_RootT, value if is_model_instance(value) else root_type.parse_obj(value)) if value is None: - none_default = root_field.default_factory() is None if root_field.default_factory \ - else root_field.default is None + default_value = root_field.get_default() + none_default = default_value is None or (is_model_instance(default_value) + and default_value.contents is None) root_type_is_none = is_none_type(root_type) root_type_is_optional = get_origin(root_type) is Union \ and any(is_none_type(arg) for arg in get_args(root_type)) diff --git a/src/omnipy/modules/general/models.py b/src/omnipy/modules/general/models.py index a0652d68..20c3e192 100644 --- a/src/omnipy/modules/general/models.py +++ b/src/omnipy/modules/general/models.py @@ -31,8 +31,12 @@ class NotIterableExceptStrOrBytesModel(Model[object | None]): """ @classmethod def _parse_data(cls, data: object) -> object: + if isinstance(data, NotIterableExceptStrOrBytesModel): + return data + assert isinstance(data, str) or isinstance(data, bytes) or not is_iterable(data), \ f'Data of type {type(data)} is iterable' + return data