Skip to content

Commit

Permalink
Amend frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Sep 2, 2024
1 parent 84f86bc commit 6f92809
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/omnipy/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions src/omnipy/modules/general/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 6f92809

Please sign in to comment.