osbot-utils 2.13.0__py3-none-any.whl → 2.14.0__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.
@@ -32,16 +32,17 @@ class Type_Safe__Convert:
32
32
  if attribute_annotation:
33
33
  origin = type_safe_cache.get_origin(attribute_annotation) # Add handling for Type[T] annotations
34
34
  if origin is type and isinstance(value, str):
35
- try: # Convert string path to actual type
36
- if len(value.rsplit('.', 1)) > 1:
37
- module_name, class_name = value.rsplit('.', 1)
38
- module = __import__(module_name, fromlist=[class_name])
39
- return getattr(module, class_name)
40
- except (ValueError, ImportError, AttributeError) as e:
41
- raise ValueError(f"Could not convert '{value}' to type: {str(e)}")
42
-
35
+ return self.get_class_from_class_name(value)
43
36
  if attribute_annotation in TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES: # for now hard-coding this to just these types until we understand the side effects
44
37
  return attribute_annotation(value)
45
38
  return value
46
39
 
40
+ def get_class_from_class_name(self, value):
41
+ try: # Convert string path to actual type
42
+ if len(value.rsplit('.', 1)) > 1:
43
+ module_name, class_name = value.rsplit('.', 1)
44
+ module = __import__(module_name, fromlist=[class_name])
45
+ return getattr(module, class_name)
46
+ except (ValueError, ImportError, AttributeError) as e:
47
+ raise ValueError(f"Could not convert '{value}' to type: {str(e)}")
47
48
  type_safe_convert = Type_Safe__Convert()
@@ -228,7 +228,10 @@ class Type_Safe__Validation:
228
228
 
229
229
  if is_invalid:
230
230
  expected_type = annotations.get(name)
231
- actual_type = type(value)
231
+ if type(value) is type:
232
+ actual_type = value
233
+ else:
234
+ actual_type = type(value)
232
235
  raise ValueError(f"Invalid type for attribute '{name}'. Expected '{expected_type}' but got '{actual_type}'")
233
236
 
234
237
  # todo: see if need to add cache support to this method (it looks like this method is not called very often)
@@ -1,11 +1,10 @@
1
- from typing import Dict, Any, Type
2
-
3
- from osbot_utils.helpers.Obj_Id import Obj_Id
4
- from osbot_utils.helpers.Random_Guid import Random_Guid
5
- from osbot_utils.type_safe.shared.Type_Safe__Cache import Type_Safe__Cache, type_safe_cache
6
- from osbot_utils.type_safe.shared.Type_Safe__Shared__Variables import IMMUTABLE_TYPES
7
- from osbot_utils.type_safe.shared.Type_Safe__Validation import type_safe_validation
8
- from osbot_utils.type_safe.steps.Type_Safe__Step__Default_Value import type_safe_step_default_value
1
+ from typing import Dict, Any, Type
2
+ from osbot_utils.helpers.Obj_Id import Obj_Id
3
+ from osbot_utils.helpers.Random_Guid import Random_Guid
4
+ from osbot_utils.type_safe.shared.Type_Safe__Cache import Type_Safe__Cache, type_safe_cache
5
+ from osbot_utils.type_safe.shared.Type_Safe__Shared__Variables import IMMUTABLE_TYPES
6
+ from osbot_utils.type_safe.shared.Type_Safe__Validation import type_safe_validation
7
+ from osbot_utils.type_safe.steps.Type_Safe__Step__Default_Value import type_safe_step_default_value
9
8
 
10
9
 
11
10
 
@@ -8,6 +8,7 @@ from osbot_utils.helpers.Random_Guid import Random_Guid
8
8
  from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
9
9
  from osbot_utils.type_safe.shared.Type_Safe__Annotations import type_safe_annotations
10
10
  from osbot_utils.type_safe.shared.Type_Safe__Cache import type_safe_cache
11
+ from osbot_utils.type_safe.shared.Type_Safe__Convert import type_safe_convert
11
12
  from osbot_utils.utils.Objects import enum_from_value
12
13
  from osbot_utils.helpers.Safe_Id import Safe_Id
13
14
  from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
@@ -43,7 +44,13 @@ class Type_Safe__Step__From_Json:
43
44
  raise ValueError(f"Attribute '{key}' not found in '{_self.__class__.__name__}'")
44
45
  else:
45
46
  continue
46
- if type_safe_annotations.obj_attribute_annotation(_self, key) == type: # Handle type objects
47
+ annotation = type_safe_annotations.obj_attribute_annotation(_self, key)
48
+ annotation_origin = type_safe_cache.get_origin(annotation)
49
+
50
+
51
+ if annotation == type: # Handle type objects
52
+ value = self.deserialize_type__using_value(value)
53
+ elif annotation_origin == type: # Handle type objects inside ForwardRef
47
54
  value = self.deserialize_type__using_value(value)
48
55
  elif type_safe_annotations.obj_is_attribute_annotation_of_type(_self, key, dict): # handle the case when the value is a dict
49
56
  value = self.deserialize_dict__using_key_value_annotations(_self, key, value)
@@ -117,6 +124,9 @@ class Type_Safe__Step__From_Json:
117
124
  if type(dict_value) == value_class: # if the value is already the target, then just use it
118
125
  new__dict_value = dict_value
119
126
  elif issubclass(value_class, Type_Safe):
127
+ if 'node_type' in dict_value:
128
+ value_class = type_safe_convert.get_class_from_class_name(dict_value['node_type'])
129
+
120
130
  new__dict_value = self.deserialize_from_dict(value_class(), dict_value)
121
131
  elif value_class is Any:
122
132
  new__dict_value = dict_value
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.13.0
1
+ v2.14.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.13.0
3
+ Version: 2.14.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  License: MIT
6
6
  Author: Dinis Cruz
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  Powerful Python util methods and classes that simplify common apis and tasks.
25
25
 
26
- ![Current Release](https://img.shields.io/badge/release-v2.13.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.14.0-blue)
27
27
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
28
28
 
29
29
 
@@ -295,16 +295,16 @@ osbot_utils/type_safe/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
295
295
  osbot_utils/type_safe/methods/type_safe_property.py,sha256=DcJkOIs6swJtkglsZVKLyFSczCGSJISOVwAmvjCOQvo,1425
296
296
  osbot_utils/type_safe/shared/Type_Safe__Annotations.py,sha256=nmVqCbhk4kUYrw_mdYqugxQlv4gM3NUUH89FYTHUg-c,1133
297
297
  osbot_utils/type_safe/shared/Type_Safe__Cache.py,sha256=G03pmpds9sTwU5z5pNLssD_GTvVSIR11nGYbkV5KaiY,7913
298
- osbot_utils/type_safe/shared/Type_Safe__Convert.py,sha256=QtO6gEGjQ5EKJOE3bsy4EiVmUGmFbMnMHxZUJh18k2s,3015
298
+ osbot_utils/type_safe/shared/Type_Safe__Convert.py,sha256=mS92_sKjKM_aNSB3ERMEgv-3DtkLVAS8AZF067G-JWM,2995
299
299
  osbot_utils/type_safe/shared/Type_Safe__Not_Cached.py,sha256=25FAl6SOLxdStco_rm9tgOYLfuKyBWheGdl7vVa56UU,800
300
300
  osbot_utils/type_safe/shared/Type_Safe__Raise_Exception.py,sha256=pbru8k8CTQMNUfmFBndiJhg2KkqEYzFvJAPcNZHeHfQ,829
301
301
  osbot_utils/type_safe/shared/Type_Safe__Shared__Variables.py,sha256=SuZGl9LryQX6IpOE0I_lbzClT-h17UNylC__-M8ltTY,129
302
- osbot_utils/type_safe/shared/Type_Safe__Validation.py,sha256=h-PwDpJ6SX8y1b7VIXB0rCY3p2nJRpeNBAvJRO8xJQQ,15960
302
+ osbot_utils/type_safe/shared/Type_Safe__Validation.py,sha256=3AtC5FpqXR4rW1LdfVyBQt3sf9opcbundxCt5Rcs7_M,16054
303
303
  osbot_utils/type_safe/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
304
- osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=bDA2hcOYsmcYwFDwNCvj5GTrLGqU78DhWtrrvDEQ2hE,6987
304
+ osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=snoyJKvZ1crgF2fp0zexwNPnV_E63RfyRIsMAZdrKNY,6995
305
305
  osbot_utils/type_safe/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
306
306
  osbot_utils/type_safe/steps/Type_Safe__Step__Default_Value.py,sha256=48-kGfkPZvhjBIEfFumigUIWWGxXe6skHgFtCCGa0LY,3987
307
- osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=vVi98VZ4Xz82Lp10SIBxSgqWuF4FM3EzrbQORMg_WWc,9347
307
+ osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=WS6HqLQCZwjpOyZ9AIl86fdB2qeqlPacsUaAkQn2rdE,9922
308
308
  osbot_utils/type_safe/steps/Type_Safe__Step__Init.py,sha256=v4FD7zxQiOFLiOF1Ma8wZMP8aLgRlXwJZnsIfBu2zeg,1266
309
309
  osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py,sha256=VuKHH9QEYlbAL9R4zwQ5dwexx2sFY6wMx52QmF7eqcg,5219
310
310
  osbot_utils/type_safe/steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -340,8 +340,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
340
340
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
341
341
  osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
342
342
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
343
- osbot_utils/version,sha256=YGrSykHz7B3et_Lt-lk1a1Wwox5GwG1-AyQ7FOE7dfw,8
344
- osbot_utils-2.13.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
345
- osbot_utils-2.13.0.dist-info/METADATA,sha256=vcJ_Y_Ij0NGdMApJS1oNxQnUq-fnaheoTLJoE-U-Nes,1329
346
- osbot_utils-2.13.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
347
- osbot_utils-2.13.0.dist-info/RECORD,,
343
+ osbot_utils/version,sha256=pPvb5XfabpwplttzVDKq3nTyCqg3sNsRXW-6GvjbCtA,8
344
+ osbot_utils-2.14.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
345
+ osbot_utils-2.14.0.dist-info/METADATA,sha256=PBFqgZgyBWg-67U3GHkfdFv5TP9Ywg6twZrGZhNMpc0,1329
346
+ osbot_utils-2.14.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
347
+ osbot_utils-2.14.0.dist-info/RECORD,,