mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-23 01:20:03 +02:00
fixes dictionary serialization for keys that are not strings
This commit is contained in:
parent
bb3d6fcce1
commit
1c1584c2cf
@ -167,10 +167,12 @@ class Serializer:
|
||||
def _serialize_dict(obj: dict[str, Any], access_path: str = "") -> SerializedDict:
|
||||
readonly = False
|
||||
doc = get_attribute_doc(obj)
|
||||
value = {
|
||||
key: Serializer.serialize_object(val, access_path=f'{access_path}["{key}"]')
|
||||
for key, val in obj.items()
|
||||
}
|
||||
value = {}
|
||||
for key, val in obj.items():
|
||||
processed_key = key if not isinstance(key, str) else f'"{key}"'
|
||||
value[key] = Serializer.serialize_object(
|
||||
val, access_path=f"{access_path}[{processed_key}]"
|
||||
)
|
||||
return {
|
||||
"full_access_path": access_path,
|
||||
"type": "dict",
|
||||
|
@ -397,7 +397,7 @@ def test_dict_serialization() -> None:
|
||||
|
||||
test_dict = {
|
||||
"int_key": 1,
|
||||
"float_key": 1.0,
|
||||
1.0: 1.0,
|
||||
"bool_key": True,
|
||||
"Quantity_key": 1.0 * u.units.s,
|
||||
"DataService_key": MyClass(),
|
||||
@ -439,8 +439,8 @@ def test_dict_serialization() -> None:
|
||||
"type": "bool",
|
||||
"value": True,
|
||||
},
|
||||
"float_key": {
|
||||
"full_access_path": '["float_key"]',
|
||||
1.0: {
|
||||
"full_access_path": "[1.0]",
|
||||
"doc": None,
|
||||
"readonly": False,
|
||||
"type": "float",
|
||||
|
Loading…
x
Reference in New Issue
Block a user