From 796a17c52c7928a3e3272fc4d0aeb5778571d13a Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Tue, 12 Mar 2024 14:51:52 +0300 Subject: [PATCH] fix: json.dumps for dicts instead of casting to str --- src/streamsync/ui_manager.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/streamsync/ui_manager.py b/src/streamsync/ui_manager.py index 5b2cda546..8e3517a4e 100644 --- a/src/streamsync/ui_manager.py +++ b/src/streamsync/ui_manager.py @@ -1,8 +1,9 @@ +from json import dumps as json_dumps from typing import Optional, Union from streamsync.core import base_component_tree -from streamsync.core_ui import (Component, SessionComponentTree, - UIError, current_parent_container) +from streamsync.core_ui import (Component, SessionComponentTree, UIError, + current_parent_container) class StreamsyncUI: @@ -57,6 +58,11 @@ def _prepare_binding(self, raw_binding): # TODO return raw_binding + def _prepare_value(self, value): + if isinstance(value, dict): + return json_dumps(value) + return str(value) + def _create_component( self, component_type: str, @@ -78,7 +84,7 @@ def _create_component( # Converting all passed content values to strings raw_content = kwargs.pop("content", {}) - content = {key: str(value) for key, value in raw_content.items()} + content = {key: self._prepare_value(value) for key, value in raw_content.items()} position: Optional[int] = kwargs.pop("position", None) is_positionless: bool = kwargs.pop("positionless", False)