DataService: updating serialize

- removing unnecessary prefix
- updating list serialization
This commit is contained in:
Mose Müller 2023-08-02 12:06:20 +02:00
parent 49d7ea30ef
commit 3352d34ec6

View File

@ -401,7 +401,7 @@ class DataService(rpyc.Service, TaskManager):
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
def serialize(self, prefix: str = "") -> dict[str, dict[str, Any]]: # noqa def serialize(self) -> dict[str, dict[str, Any]]: # noqa
""" """
Serializes the instance into a dictionary, preserving the structure of the Serializes the instance into a dictionary, preserving the structure of the
instance. instance.
@ -463,9 +463,6 @@ class DataService(rpyc.Service, TaskManager):
# Get the value of the current attribute or method # Get the value of the current attribute or method
value = getattr(self, key) value = getattr(self, key)
# Prepare the key by appending prefix and the key
key = f"{prefix}.{key}" if prefix else key
if isinstance(value, DataService): if isinstance(value, DataService):
result[key] = { result[key] = {
"type": type(value).__name__ "type": type(value).__name__
@ -480,8 +477,11 @@ class DataService(rpyc.Service, TaskManager):
"type": "list", "type": "list",
"value": [ "value": [
{ {
"type": type(item).__name__, "type": "DataService"
"value": item.serialize(prefix=key) if isinstance(item, DataService)
and type(item).__name__ not in ("NumberSlider")
else type(item).__name__,
"value": item.serialize()
if isinstance(item, DataService) if isinstance(item, DataService)
else item, else item,
"readonly": False, "readonly": False,