Skip to content

Commit

Permalink
Refactor Model.__getattr__
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Sep 2, 2024
1 parent e699277 commit dacc21d
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/omnipy/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,29 +1321,23 @@ def _fix_tuple_type_from_args(
return level_up_type_to_check

def __getattr__(self, attr: str) -> Any:
contents_attr = self._getattr_from_contents_obj(attr)

reset_solution = self._prepare_validation_reset_solution_take_snapshot_if_needed()

if self._is_non_omnipy_pydantic_model():
reset_solution = self._prepare_validation_reset_solution_take_snapshot_if_needed()

if self._contents_obj_hasattr(attr):
self._validate_and_set_value(self.contents, reset_solution=reset_solution)

is_property = False
with suppress(AttributeError):
contents_cls_attr = self._getattr_from_contents_cls(attr)
is_property = isinstance(contents_cls_attr, property)

reset_solution = self._prepare_validation_reset_solution_take_snapshot_if_needed()
contents_attr = self._getattr_from_contents_obj(attr)

if callable(contents_attr) and not is_property:
if inspect.isroutine(contents_attr):
reset_solution = self._prepare_validation_reset_solution_take_snapshot_if_needed()
new_contents_attr = self._getattr_from_contents_obj(attr)

def _validate_contents(ret: Any):
self._validate_and_set_value(self.contents, reset_solution=reset_solution)
return ret

contents_attr = add_callback_after_call(contents_attr,
contents_attr = add_callback_after_call(new_contents_attr,
_validate_contents,
reset_solution)

Expand Down

0 comments on commit dacc21d

Please sign in to comment.