aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2023-09-13 11:44:12 +0200
committerThéo de la Hogue2023-09-13 11:44:12 +0200
commitdfa02fde90ad01e32bbf20335243e607291fdeef (patch)
tree19ad4a39acb26ad6a869b4b0c5f57c7126bb84ca /src
parentd44f851b16e8ca5bc1222dead01c3aeb55c82f72 (diff)
downloadargaze-dfa02fde90ad01e32bbf20335243e607291fdeef.zip
argaze-dfa02fde90ad01e32bbf20335243e607291fdeef.tar.gz
argaze-dfa02fde90ad01e32bbf20335243e607291fdeef.tar.bz2
argaze-dfa02fde90ad01e32bbf20335243e607291fdeef.tar.xz
Fixing as_dict function.
Diffstat (limited to 'src')
-rw-r--r--src/argaze/DataStructures.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index e6dfc8b..08a7d2c 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -8,7 +8,7 @@ __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from typing import TypeVar, Tuple
-from dataclasses import asdict
+from inspect import getmembers
import collections
import json
import ast
@@ -30,13 +30,20 @@ TimeStampedBufferType = TypeVar('TimeStampedBuffer', bound="TimeStampedBuffer")
def as_dict(dataclass_object) -> dict:
"""
- Get dataclass object attributes values as a dictionary.
+ Get dataclass object fields's values as a dictionary.
Returns:
- values: dictionary of dataclass attributes values
+ values: dictionary of dataclass fields's values
"""
- return {key: vars(dataclass_object)[key] for key in asdict(dataclass_object).keys()}
+ # Get data class fields names
+ fields_names = []
+ for member_name, member_value in getmembers(dataclass_object):
+ if member_name == '__dataclass_fields__':
+ fields_names = member_value.keys()
+
+ # Copy fields values
+ return {name: vars(dataclass_object)[name] for name in fields_names}
class JsonEncoder(json.JSONEncoder):
"""Specific ArGaze JSON Encoder."""