trd-utils 0.0.5__tar.gz → 0.0.6__tar.gz

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.

Files changed (24) hide show
  1. {trd_utils-0.0.5 → trd_utils-0.0.6}/PKG-INFO +1 -1
  2. {trd_utils-0.0.5 → trd_utils-0.0.6}/pyproject.toml +1 -1
  3. trd_utils-0.0.6/trd_utils/__init__.py +3 -0
  4. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/types_helper/base_model.py +31 -19
  5. trd_utils-0.0.5/trd_utils/__init__.py +0 -3
  6. {trd_utils-0.0.5 → trd_utils-0.0.6}/LICENSE +0 -0
  7. {trd_utils-0.0.5 → trd_utils-0.0.6}/README.md +0 -0
  8. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/cipher/__init__.py +0 -0
  9. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/common_utils/float_utils.py +0 -0
  10. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/__init__.py +0 -0
  11. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/blofin/__init__.py +0 -0
  12. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/blofin/blofin_client.py +0 -0
  13. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/blofin/blofin_types.py +0 -0
  14. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/bx_ultra/__init__.py +0 -0
  15. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/bx_ultra/bx_types.py +0 -0
  16. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/bx_ultra/bx_ultra_client.py +0 -0
  17. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/bx_ultra/bx_utils.py +0 -0
  18. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/exchanges/exchange_base.py +0 -0
  19. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/html_utils/__init__.py +0 -0
  20. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/html_utils/html_formats.py +0 -0
  21. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/tradingview/__init__.py +0 -0
  22. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/tradingview/tradingview_client.py +0 -0
  23. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/tradingview/tradingview_types.py +0 -0
  24. {trd_utils-0.0.5 → trd_utils-0.0.6}/trd_utils/types_helper/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: trd_utils
3
- Version: 0.0.5
3
+ Version: 0.0.6
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "trd_utils"
3
- version = "0.0.5"
3
+ version = "0.0.6"
4
4
  description = "Common Basic Utils for Python3. By ALiwoto."
5
5
  authors = ["ALiwoto <aminnimaj@gmail.com>"]
6
6
  packages = [
@@ -0,0 +1,3 @@
1
+
2
+ __version__ = "0.0.6"
3
+
@@ -3,7 +3,7 @@ from typing import (
3
3
  Union,
4
4
  get_type_hints,
5
5
  Any,
6
- get_args as get_type_args
6
+ get_args as get_type_args,
7
7
  )
8
8
 
9
9
  from trd_utils.html_utils.html_formats import camel_to_snake
@@ -19,6 +19,7 @@ ULTRA_LIST_ENABLED: bool = False
19
19
  # attribute names are converted to snake_case.
20
20
  SET_CAMEL_ATTR_NAMES = False
21
21
 
22
+
22
23
  def get_my_field_types(cls):
23
24
  type_hints = {}
24
25
  for current_cls in cls.__class__.__mro__:
@@ -27,24 +28,31 @@ def get_my_field_types(cls):
27
28
  type_hints.update(get_type_hints(current_cls))
28
29
  return type_hints
29
30
 
31
+
30
32
  def get_real_attr(cls, attr_name):
31
33
  if cls is None:
32
34
  return None
33
-
35
+
34
36
  if isinstance(cls, dict):
35
37
  return cls.get(attr_name, None)
36
38
 
37
39
  if hasattr(cls, attr_name):
38
40
  return getattr(cls, attr_name)
39
-
41
+
40
42
  return None
41
43
 
44
+
45
+ def is_any_type(target_type: type) -> bool:
46
+ return target_type == Any or target_type is type(None)
47
+
48
+
42
49
  class UltraList(list):
43
50
  def __getattr__(self, attr):
44
51
  if len(self) == 0:
45
52
  return None
46
53
  return UltraList([get_real_attr(item, attr) for item in self])
47
54
 
55
+
48
56
  def convert_to_ultra_list(value: Any) -> UltraList:
49
57
  if not value:
50
58
  return UltraList()
@@ -61,7 +69,7 @@ def convert_to_ultra_list(value: Any) -> UltraList:
61
69
  return tuple(convert_to_ultra_list(v) for v in value)
62
70
  elif isinstance(value, set):
63
71
  return {convert_to_ultra_list(v) for v in value}
64
-
72
+
65
73
  for attr, attr_value in get_my_field_types(value).items():
66
74
  if isinstance(attr_value, list):
67
75
  setattr(value, attr, convert_to_ultra_list(getattr(value, attr)))
@@ -70,6 +78,7 @@ def convert_to_ultra_list(value: Any) -> UltraList:
70
78
  except Exception:
71
79
  return value
72
80
 
81
+
73
82
  class BaseModel:
74
83
  def __init__(self, **kwargs):
75
84
  annotations = get_my_field_types(self)
@@ -83,17 +92,19 @@ class BaseModel:
83
92
  # just ignore and continue
84
93
  annotations[key] = Any
85
94
  annotations[corrected_key] = Any
86
-
95
+
87
96
  expected_type = annotations[corrected_key]
88
97
  if hasattr(self, "_get_" + corrected_key + "_type"):
89
98
  try:
90
- overridden_type = getattr(self, "_get_" + corrected_key + "_type")(kwargs)
99
+ overridden_type = getattr(self, "_get_" + corrected_key + "_type")(
100
+ kwargs
101
+ )
91
102
  if overridden_type:
92
103
  expected_type = overridden_type
93
104
  except Exception:
94
105
  pass
95
-
96
- is_optional_type = getattr(expected_type, '_name', None) == 'Optional'
106
+
107
+ is_optional_type = getattr(expected_type, "_name", None) == "Optional"
97
108
  # maybe in the future we can have some other usages for is_optional_type
98
109
  # variable or something like that.
99
110
  if is_optional_type:
@@ -102,11 +113,11 @@ class BaseModel:
102
113
  except Exception:
103
114
  # something went wrong, just ignore and continue
104
115
  expected_type = Any
105
-
116
+
106
117
  # Handle nested models
107
118
  if isinstance(value, dict) and issubclass(expected_type, BaseModel):
108
119
  value = expected_type(**value)
109
-
120
+
110
121
  elif isinstance(value, list):
111
122
  type_args = get_type_args(expected_type)
112
123
  if not type_args:
@@ -118,27 +129,29 @@ class BaseModel:
118
129
  nested_type = type_args[0]
119
130
  if issubclass(nested_type, BaseModel):
120
131
  value = [nested_type(**item) for item in value]
121
-
132
+
122
133
  if ULTRA_LIST_ENABLED and isinstance(value, list):
123
134
  value = convert_to_ultra_list(value)
124
-
135
+
125
136
  # Type checking
126
- elif expected_type != Any and not isinstance(value, expected_type):
137
+ elif not (is_any_type(expected_type) or isinstance(value, expected_type)):
127
138
  try:
128
139
  value = expected_type(value)
129
140
  except Exception:
130
- raise TypeError(f"Field {corrected_key} must be of type {expected_type}," +
131
- f" but it's {type(value)}")
132
-
141
+ raise TypeError(
142
+ f"Field {corrected_key} must be of type {expected_type},"
143
+ + f" but it's {type(value)}"
144
+ )
145
+
133
146
  setattr(self, corrected_key, value)
134
147
  if SET_CAMEL_ATTR_NAMES and key != corrected_key:
135
148
  setattr(self, key, value)
136
-
149
+
137
150
  # Check if all required fields are present
138
151
  # for field in self.__annotations__:
139
152
  # if not hasattr(self, field):
140
153
  # raise ValueError(f"Missing required field: {field}")
141
-
154
+
142
155
  @classmethod
143
156
  def deserialize(cls, json_data: Union[str, dict]):
144
157
  if isinstance(json_data, str):
@@ -146,4 +159,3 @@ class BaseModel:
146
159
  else:
147
160
  data = json_data
148
161
  return cls(**data)
149
-
@@ -1,3 +0,0 @@
1
-
2
- __version__ = "0.0.5"
3
-
File without changes
File without changes