trd-utils 0.0.25__py3-none-any.whl → 0.0.26__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 +15 -4
- {trd_utils-0.0.25.dist-info → trd_utils-0.0.26.dist-info}/METADATA +1 -1
- {trd_utils-0.0.25.dist-info → trd_utils-0.0.26.dist-info}/RECORD +6 -6
- {trd_utils-0.0.25.dist-info → trd_utils-0.0.26.dist-info}/LICENSE +0 -0
- {trd_utils-0.0.25.dist-info → trd_utils-0.0.26.dist-info}/WHEEL +0 -0
trd_utils/__init__.py
CHANGED
|
@@ -47,6 +47,14 @@ def get_real_attr(cls, attr_name):
|
|
|
47
47
|
return None
|
|
48
48
|
|
|
49
49
|
|
|
50
|
+
def is_base_model_type(expected_type: type) -> bool:
|
|
51
|
+
return (
|
|
52
|
+
expected_type is not None
|
|
53
|
+
and expected_type != Any
|
|
54
|
+
and issubclass(expected_type, BaseModel)
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
50
58
|
def is_any_type(target_type: type) -> bool:
|
|
51
59
|
return target_type == Any or target_type is type(None)
|
|
52
60
|
|
|
@@ -92,16 +100,17 @@ def value_to_normal_obj(value, omit_none: bool = False):
|
|
|
92
100
|
result[inner_key] = normalized_value
|
|
93
101
|
|
|
94
102
|
return result
|
|
95
|
-
|
|
103
|
+
|
|
96
104
|
if isinstance(value, datetime.datetime):
|
|
97
105
|
return dt_to_ts(value)
|
|
98
106
|
|
|
99
107
|
raise TypeError(f"unsupported type provided: {type(value)}")
|
|
100
108
|
|
|
109
|
+
|
|
101
110
|
def convert_to_expected_type(
|
|
102
111
|
expected_type: type,
|
|
103
112
|
value: Any,
|
|
104
|
-
default_value
|
|
113
|
+
default_value=None,
|
|
105
114
|
):
|
|
106
115
|
try:
|
|
107
116
|
return expected_type(value)
|
|
@@ -148,7 +157,7 @@ def generic_obj_to_value(
|
|
|
148
157
|
)
|
|
149
158
|
return result
|
|
150
159
|
|
|
151
|
-
if isinstance(value, dict) and
|
|
160
|
+
if isinstance(value, dict) and is_base_model_type(expected_type=expected_type):
|
|
152
161
|
if len(expected_type_args) > 1:
|
|
153
162
|
raise ValueError(
|
|
154
163
|
"unsupported operation: at this time we cannot have"
|
|
@@ -249,7 +258,9 @@ class BaseModel:
|
|
|
249
258
|
)
|
|
250
259
|
|
|
251
260
|
# Handle nested models
|
|
252
|
-
elif isinstance(value, dict) and
|
|
261
|
+
elif isinstance(value, dict) and is_base_model_type(
|
|
262
|
+
expected_type=expected_type
|
|
263
|
+
):
|
|
253
264
|
value = expected_type(**value)
|
|
254
265
|
|
|
255
266
|
elif isinstance(value, list):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
trd_utils/__init__.py,sha256=
|
|
1
|
+
trd_utils/__init__.py,sha256=Wy_DfSBoQg4JGnSX4I-RPMxCXnRcYWQW07O41KIS8LM,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/common_utils/wallet_utils.py,sha256=OX9q2fymP0VfIWTRIRBP8W33cfyjLXimxMgPOsZe-3g,727
|
|
@@ -28,8 +28,8 @@ trd_utils/tradingview/__init__.py,sha256=H0QYb-O5qvy7qC3yswtlcSWLmeBnaS6oJ3Jtjvm
|
|
|
28
28
|
trd_utils/tradingview/tradingview_client.py,sha256=g_eWYaCRQAL8Kvd-r6AnAdbH7Jha6C_GAyCuxh-RQUU,3917
|
|
29
29
|
trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
|
|
30
30
|
trd_utils/types_helper/__init__.py,sha256=lLbUiW1jUV1gjzTMFLthwkvF0hwauH-F_J2JZq--1U0,67
|
|
31
|
-
trd_utils/types_helper/base_model.py,sha256=
|
|
32
|
-
trd_utils-0.0.
|
|
33
|
-
trd_utils-0.0.
|
|
34
|
-
trd_utils-0.0.
|
|
35
|
-
trd_utils-0.0.
|
|
31
|
+
trd_utils/types_helper/base_model.py,sha256=Q2KK0r4UXP9PlWeIl6nxdAeCGB5InU5IkTNGAfJasfM,11808
|
|
32
|
+
trd_utils-0.0.26.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
|
|
33
|
+
trd_utils-0.0.26.dist-info/METADATA,sha256=CorynlnCD_2-PAjDTKSRYOdkt61sShVt-KqZlSQxSKo,1095
|
|
34
|
+
trd_utils-0.0.26.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
35
|
+
trd_utils-0.0.26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|