Skip to content
Snippets Groups Projects
Commit 7ff0eb0a authored by Yakubov, Sergey's avatar Yakubov, Sergey
Browse files

change isinstance check to issublass

parent 0fc4a406
No related branches found
No related tags found
1 merge request!6Update library to work with Pydantic models
Pipeline #640845 waiting for manual action
......@@ -10,7 +10,8 @@ bindings_map: Dict[str, Any] = {}
def update_bindings_map(source: Any, value: Any) -> None:
if isinstance(source, BaseModel):
# if isinstance(source, BaseModel):
if issubclass(type(source), BaseModel):
fields = rget_list_of_fields(source)
for field in fields:
bindings_map[field] = value
"""Abstract interfaces and type definitions."""
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, Optional, Union
from typing import Any, Callable, Optional, Union
LinkedObjectType = Optional[Union[object, Dict[str, Any], Callable]]
LinkedObjectType = Optional[Any]
LinkedObjectAttributesType = Optional[list[str]]
CallbackAfterUpdateType = Optional[Callable[[Optional[str]], None]]
ConnectCallbackType = Union[None, Callable[[Any, Optional[str]], None]]
......
......@@ -41,7 +41,7 @@ class Communicator(QObject):
self.callback_after_update = callback_after_update
def _update_viewmodel_callback(self, key: Optional[str] = None, value: Any = None) -> None:
if isinstance(self.viewmodel_linked_object, BaseModel):
if issubclass(type(value), BaseModel):
model = self.viewmodel_linked_object.copy(deep=True)
rsetattr(model, key or "", value)
try:
......
......@@ -58,7 +58,7 @@ class TrameCommunicator(Communicator):
if (
viewmodel_linked_object
and not isinstance(viewmodel_linked_object, dict)
and not isinstance(viewmodel_linked_object, BaseModel)
and not issubclass(type(viewmodel_linked_object), BaseModel)
and not is_callable(viewmodel_linked_object)
):
if not linked_object_attributes:
......@@ -90,7 +90,7 @@ class CallBackConnection:
self.linked_object_attributes = communicator.linked_object_attributes
def _update_viewmodel_callback(self, value: Any, key: Optional[str] = None) -> None:
if isinstance(self.viewmodel_linked_object, BaseModel):
if self.viewmodel_linked_object and issubclass(type(self.viewmodel_linked_object), BaseModel):
model = self.viewmodel_linked_object.copy(deep=True)
rsetattr(model, key or "", value)
try:
......@@ -179,7 +179,7 @@ class StateConnection:
@self.state.change(state_variable_name)
def update_viewmodel_callback(**kwargs: dict) -> None:
success = True
if isinstance(self.viewmodel_linked_object, BaseModel):
if self.viewmodel_linked_object and issubclass(type(self.viewmodel_linked_object), BaseModel):
json_str = json.dumps(kwargs[state_variable_name])
try:
model = self.viewmodel_linked_object.model_validate_json(json_str)
......@@ -197,7 +197,7 @@ class StateConnection:
self.viewmodel_callback_after_update(state_variable_name)
def update_in_view(self, value: Any) -> None:
if hasattr(value, "model_dump"):
if issubclass(type(value), BaseModel):
value = value.model_dump()
if self.linked_object_attributes:
for attribute_name in self.linked_object_attributes:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment