trd-utils 0.0.47__py3-none-any.whl → 0.0.48__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 CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- __version__ = "0.0.47"
2
+ __version__ = "0.0.48"
3
3
 
@@ -13,7 +13,7 @@ from trd_utils.date_utils.datetime_helpers import dt_from_ts, dt_to_ts
13
13
  from trd_utils.html_utils.html_formats import camel_to_snake
14
14
  from trd_utils.types_helper.model_config import ModelConfig
15
15
  from trd_utils.types_helper.ultra_list import convert_to_ultra_list
16
- from trd_utils.types_helper.utils import AbstractModel, get_my_field_types
16
+ from trd_utils.types_helper.utils import AbstractModel, get_my_field_types, is_type_optional
17
17
 
18
18
  # Whether to use ultra-list instead of normal python list or not.
19
19
  # This might be convenient in some cases, but it is not recommended
@@ -199,7 +199,7 @@ class BaseModel(AbstractModel):
199
199
 
200
200
  expected_type_args = get_type_args(expected_type)
201
201
  expected_type_name = getattr(expected_type, "__name__", None)
202
- is_optional_type = expected_type_name == "Optional"
202
+ is_optional_type = is_type_optional(expected_type)
203
203
  is_dict_type = expected_type_name == "dict"
204
204
  # maybe in the future we can have some other usages for is_optional_type
205
205
  # variable or something like that.
@@ -278,9 +278,16 @@ class BaseModel(AbstractModel):
278
278
  # raise ValueError(f"Missing required field: {field}")
279
279
 
280
280
  @classmethod
281
- def deserialize(cls, json_data: Union[str, dict]):
281
+ def deserialize(
282
+ cls,
283
+ json_data: Union[str, dict],
284
+ parse_float=Decimal,
285
+ ):
282
286
  if isinstance(json_data, str):
283
- data = json.loads(json_data)
287
+ data = json.loads(
288
+ json_data,
289
+ parse_float=parse_float,
290
+ )
284
291
  else:
285
292
  data = json_data
286
293
  return cls(**data)
@@ -5,6 +5,18 @@ from typing import (
5
5
  class AbstractModel:
6
6
  pass
7
7
 
8
+ def is_type_optional(target: type) -> bool:
9
+ if getattr(target, "__name__", None) == "Optional":
10
+ # e.g: my_field: Optional[str] = None
11
+ return True
12
+
13
+ target_args = getattr(target, "__args__", None)
14
+ if target_args and len(target_args) > 1 and target_args[1] is type(None):
15
+ # e.g: my_field: Decimal | None = None
16
+ return True
17
+
18
+ return False
19
+
8
20
  def get_real_attr(cls, attr_name):
9
21
  if cls is None:
10
22
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: trd_utils
3
- Version: 0.0.47
3
+ Version: 0.0.48
4
4
  Summary: Common Basic Utils for Python3. By ALiwoto.
5
5
  Keywords: utils,trd_utils,basic-utils,common-utils
6
6
  Author: ALiwoto
@@ -1,4 +1,4 @@
1
- trd_utils/__init__.py,sha256=7UU7HS7yxJAEYyOKLnxUasYKfDeCqB9WVSiQaW6z6r0,25
1
+ trd_utils/__init__.py,sha256=F6nqO7h9gFbxijcrf5rruAh2gbKqWBYRYodKJG82pGA,25
2
2
  trd_utils/cipher/__init__.py,sha256=V05KNuzQwCic-ihMVHlC8sENaJGc3I8MCb4pg4849X8,1765
3
3
  trd_utils/common_utils/float_utils.py,sha256=aYPwJ005LmrRhXAngojwvdDdtRgeb1FfR6hKeQ5ndMU,470
4
4
  trd_utils/common_utils/wallet_utils.py,sha256=OX9q2fymP0VfIWTRIRBP8W33cfyjLXimxMgPOsZe-3g,727
@@ -30,12 +30,12 @@ trd_utils/tradingview/__init__.py,sha256=H0QYb-O5qvy7qC3yswtlcSWLmeBnaS6oJ3Jtjvm
30
30
  trd_utils/tradingview/tradingview_client.py,sha256=g_eWYaCRQAL8Kvd-r6AnAdbH7Jha6C_GAyCuxh-RQUU,3917
31
31
  trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
32
32
  trd_utils/types_helper/__init__.py,sha256=cVm7Pbvuow4zS9vvH4cI9TQjRjPf_d1JE15zXb6dG40,188
33
- trd_utils/types_helper/base_model.py,sha256=5y_QHYiNu57IxYtyFpPUNA3HI9Jywryl8cyxbM5jQcI,11066
33
+ trd_utils/types_helper/base_model.py,sha256=A1AGScpvnpxdf_sCD4PLc6bbd6MSeOEUQ-FoEuU7PaQ,11207
34
34
  trd_utils/types_helper/decorators.py,sha256=ziQGDKV0RnhMG6gBPAz244Ug3j6ayr0iKXeucAdnXB8,527
35
35
  trd_utils/types_helper/model_config.py,sha256=uvyhdGHQZ1A_I5RUbCgzlDk6MxWL6RLV8r0cdVi6nBk,60
36
36
  trd_utils/types_helper/ultra_list.py,sha256=01WQSkx0G7lD9O9XcXccexniNwyuQ9LwVOeixxr4tWQ,1178
37
- trd_utils/types_helper/utils.py,sha256=Xq4SZG4NkkGzJyOBs9huAvzl2YcCZ7ZRjfOHol3o-Kc,569
38
- trd_utils-0.0.47.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
39
- trd_utils-0.0.47.dist-info/METADATA,sha256=XVe1RaP3QDNuatLXmKdUN4ksyhE8nvYK1Xn_Lk92A88,1179
40
- trd_utils-0.0.47.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
41
- trd_utils-0.0.47.dist-info/RECORD,,
37
+ trd_utils/types_helper/utils.py,sha256=hJzxI6D1ZSmv4y4wLrv-QW5AvrDU4BARXJmLpB-CTEI,960
38
+ trd_utils-0.0.48.dist-info/LICENSE,sha256=J1EP2xt87RjjmsTV1jTjHDQMLIM9FjdwEftTpw8hyv4,1067
39
+ trd_utils-0.0.48.dist-info/METADATA,sha256=GKHCGk74bb8OZ7UVLSV9hte6gaNQm9rb67mHJz0wxns,1179
40
+ trd_utils-0.0.48.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
41
+ trd_utils-0.0.48.dist-info/RECORD,,