trd-utils 0.0.8__py3-none-any.whl → 0.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of trd-utils might be problematic. Click here for more details.
- trd_utils/__init__.py +1 -1
- trd_utils/types_helper/base_model.py +26 -10
- {trd_utils-0.0.8.dist-info → trd_utils-0.0.10.dist-info}/METADATA +1 -1
- {trd_utils-0.0.8.dist-info → trd_utils-0.0.10.dist-info}/RECORD +6 -6
- {trd_utils-0.0.8.dist-info → trd_utils-0.0.10.dist-info}/LICENSE +0 -0
- {trd_utils-0.0.8.dist-info → trd_utils-0.0.10.dist-info}/WHEEL +0 -0
trd_utils/__init__.py
CHANGED
|
@@ -48,7 +48,7 @@ def is_any_type(target_type: type) -> bool:
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
# TODO: add support for max_depth for this...
|
|
51
|
-
def value_to_normal_obj(value):
|
|
51
|
+
def value_to_normal_obj(value, omit_none: bool = False,):
|
|
52
52
|
"""
|
|
53
53
|
Converts a custom value, to a corresponding "normal object" which can be used
|
|
54
54
|
in dict.
|
|
@@ -71,7 +71,11 @@ def value_to_normal_obj(value):
|
|
|
71
71
|
if isinstance(value, dict):
|
|
72
72
|
result = {}
|
|
73
73
|
for inner_key, inner_value in value.items():
|
|
74
|
-
|
|
74
|
+
normalized_value = value_to_normal_obj(inner_value)
|
|
75
|
+
if normalized_value is None and omit_none:
|
|
76
|
+
continue
|
|
77
|
+
|
|
78
|
+
result[inner_key] = normalized_value
|
|
75
79
|
|
|
76
80
|
return result
|
|
77
81
|
|
|
@@ -92,11 +96,13 @@ def generic_obj_to_value(
|
|
|
92
96
|
if isinstance(value, list):
|
|
93
97
|
result = []
|
|
94
98
|
for current in value:
|
|
95
|
-
result.append(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
result.append(
|
|
100
|
+
generic_obj_to_value(
|
|
101
|
+
expected_type=expected_type_args[0],
|
|
102
|
+
expected_type_args=expected_type_args[1:],
|
|
103
|
+
value=current,
|
|
104
|
+
)
|
|
105
|
+
)
|
|
100
106
|
return result
|
|
101
107
|
|
|
102
108
|
expected_type_name = getattr(expected_type, "__name__", None)
|
|
@@ -266,16 +272,26 @@ class BaseModel:
|
|
|
266
272
|
sort_keys=sort_keys,
|
|
267
273
|
)
|
|
268
274
|
|
|
269
|
-
def to_dict(
|
|
275
|
+
def to_dict(
|
|
276
|
+
self,
|
|
277
|
+
omit_none: bool = False,
|
|
278
|
+
) -> dict:
|
|
270
279
|
annotations = get_my_field_types(self)
|
|
271
280
|
result_dict = {}
|
|
272
281
|
for key, _ in annotations.items():
|
|
273
282
|
if not isinstance(key, str):
|
|
274
283
|
continue
|
|
275
284
|
|
|
276
|
-
if key.startswith("__"):
|
|
285
|
+
if key.startswith("__") or key.startswith(f"_{self.__class__.__name__}__"):
|
|
277
286
|
# ignore private attributes
|
|
278
287
|
continue
|
|
279
288
|
|
|
280
|
-
|
|
289
|
+
normalized_value = value_to_normal_obj(
|
|
290
|
+
value=getattr(self, key),
|
|
291
|
+
omit_none=omit_none,
|
|
292
|
+
)
|
|
293
|
+
if normalized_value is None and omit_none:
|
|
294
|
+
continue
|
|
295
|
+
|
|
296
|
+
result_dict[key] = normalized_value
|
|
281
297
|
return result_dict
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
trd_utils/__init__.py,sha256=
|
|
1
|
+
trd_utils/__init__.py,sha256=s-ocGd3ICilpBOX4pI4QXz9Ne-ywBoxqkjVooU2gnQE,25
|
|
2
2
|
trd_utils/cipher/__init__.py,sha256=V05KNuzQwCic-ihMVHlC8sENaJGc3I8MCb4pg4849X8,1765
|
|
3
3
|
trd_utils/common_utils/float_utils.py,sha256=W-jv7nzjl88xwGB6gsEXmDDhF6DseOrrVT2qx7OvyCo,266
|
|
4
4
|
trd_utils/exchanges/__init__.py,sha256=SQJt5cIXh305miWuDumkOLZHzqDUyOqSmlhTT9Xc9RY,180
|
|
@@ -16,8 +16,8 @@ trd_utils/tradingview/__init__.py,sha256=H0QYb-O5qvy7qC3yswtlcSWLmeBnaS6oJ3Jtjvm
|
|
|
16
16
|
trd_utils/tradingview/tradingview_client.py,sha256=g_eWYaCRQAL8Kvd-r6AnAdbH7Jha6C_GAyCuxh-RQUU,3917
|
|
17
17
|
trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
|
|
18
18
|
trd_utils/types_helper/__init__.py,sha256=VlEXDzOyn6fYH-dE86EGJ6u_el08QvdyOtJkj-0EAVA,65
|
|
19
|
-
trd_utils/types_helper/base_model.py,sha256=
|
|
20
|
-
trd_utils-0.0.
|
|
21
|
-
trd_utils-0.0.
|
|
22
|
-
trd_utils-0.0.
|
|
23
|
-
trd_utils-0.0.
|
|
19
|
+
trd_utils/types_helper/base_model.py,sha256=gtMKbX47V5eKMwllVha50G9WfQ7Ci-9dXAw5vsrtLSo,9814
|
|
20
|
+
trd_utils-0.0.10.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
|
|
21
|
+
trd_utils-0.0.10.dist-info/METADATA,sha256=g3IxPgftl-BKCCzcoW_fkfxIiLQ-BI3QF1lw0qtm3-s,1095
|
|
22
|
+
trd_utils-0.0.10.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
23
|
+
trd_utils-0.0.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|