osbot-utils 2.87.0__py3-none-any.whl → 2.88.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.
@@ -88,7 +88,7 @@ class Type_Safe:
88
88
  if value is not None:
89
89
  if hasattr(self,'__annotations__'): # can only do type safety checks if the class does not have annotations
90
90
  if type_safe_validation.check_if__type_matches__obj_annotation__for_attr(self, key, value) is False:
91
- raise ValueError(f"Invalid type for attribute '{key}'. Expected '{self.__annotations__.get(key)}' but got '{type(value)}'")
91
+ raise ValueError(f"On {self.__class__.__name__} invalid type for attribute '{key}'. Expected '{self.__annotations__.get(key)}' but got '{type(value)}'")
92
92
  setattr(self, key, value)
93
93
  return self
94
94
 
@@ -3,8 +3,12 @@ from osbot_utils.type_safe.type_safe_core.shared.Type_Safe__Shared__Variables im
3
3
 
4
4
  class Type_Safe__Raise_Exception:
5
5
 
6
- def type_mismatch_error(self, var_name: str, expected_type: type, actual_type: type) -> None: # Raises formatted error for type validation failures
7
- exception_message = f"Invalid type for attribute '{var_name}'. Expected '{expected_type}' but got '{actual_type}'"
6
+ def type_mismatch_error__on_instance(self, _self, var_name: str, expected_type: type, actual_type: type) -> None: # Raises formatted error for type validation failures
7
+ exception_message = f"On {_self.__class__.__name__}, invalid type for attribute '{var_name}'. Expected '{expected_type}' but got '{actual_type}'"
8
+ raise ValueError(exception_message) from None
9
+
10
+ def type_mismatch_error__on_type(self, cls, var_name: str, expected_type: type, actual_type: type) -> None: # Raises formatted error for type validation failures
11
+ exception_message = f"On {cls.__name__}, invalid type for attribute '{var_name}'. Expected '{expected_type}' but got '{actual_type}'"
8
12
  raise ValueError(exception_message) from None
9
13
 
10
14
  def immutable_type_error(self, var_name, var_type):
@@ -270,11 +270,11 @@ class Type_Safe__Validation:
270
270
  def validate_if_value_has_been_set(self, _self, annotations, name, value):
271
271
  if hasattr(_self, name) and annotations.get(name) : # don't allow previously set variables to be set to None
272
272
  if getattr(_self, name) is not None: # unless it is already set to None
273
- raise ValueError(f"Can't set None, to a variable that is already set. Invalid type for attribute '{name}'. Expected '{_self.__annotations__.get(name)}' but got '{type(value)}'")
273
+ raise ValueError(f"On {_self.__class__.__name__}, can't be set to None, to a variable that is already set. Invalid type for attribute '{name}'. Expected '{_self.__annotations__.get(name)}' but got '{type(value)}'")
274
274
 
275
- def validate_if__types_are_compatible_for_assigment(self, name, current_type, expected_type):
275
+ def validate_if__types_are_compatible_for_assigment(self, _self, name, current_type, expected_type):
276
276
  if not type_safe_validation.are_types_compatible_for_assigment(current_type, expected_type):
277
- type_safe_raise_exception.type_mismatch_error(name, expected_type, current_type)
277
+ type_safe_raise_exception.type_mismatch_error__on_instance(_self, name, expected_type, current_type)
278
278
 
279
279
  def validate_type_compatibility(self, target : Any , # Target object to validate
280
280
  annotations : Dict[str, Any] , # Type annotations
@@ -295,7 +295,7 @@ class Type_Safe__Validation:
295
295
  actual_type = value
296
296
  else:
297
297
  actual_type = type(value)
298
- raise ValueError(f"Invalid type for attribute '{name}'. Expected '{expected_type}' but got '{actual_type}'") from None
298
+ raise ValueError(f"On {target.__class__.__name__}, invalid type for attribute '{name}'. Expected '{expected_type}' but got '{actual_type}'") from None
299
299
 
300
300
  # todo: see if need to add cache support to this method (it looks like this method is not called very often)
301
301
  def validate_type_immutability(self, var_name: str, var_type: Any) -> None: # Validates that type is immutable or in supported format
@@ -321,8 +321,8 @@ class Type_Safe__Validation:
321
321
  # if not (isinstance(var_type, type) and issubclass(var_type, (int,str, float))):
322
322
  # type_safe_raise_exception.immutable_type_error(var_name, var_type)
323
323
 
324
- def validate_variable_type(self, var_name, var_type, var_value): # Validate type compatibility
324
+ def validate_variable_type(self, base_cls, var_name, var_type, var_value): # Validate type compatibility
325
325
  if type(var_type) is type and not isinstance(var_value, var_type):
326
- type_safe_raise_exception.type_mismatch_error(var_name, var_type, type(var_value))
326
+ type_safe_raise_exception.type_mismatch_error__on_type(base_cls, var_name, var_type, type(var_value))
327
327
 
328
328
  type_safe_validation = Type_Safe__Validation()
@@ -96,7 +96,7 @@ class Type_Safe__Step__Class_Kwargs:
96
96
  # If conversion fails, let the original validation handle it
97
97
  pass
98
98
 
99
- type_safe_validation.validate_variable_type(var_name, var_type, var_value)
99
+ type_safe_validation.validate_variable_type(base_cls, var_name, var_type, var_value)
100
100
  type_safe_validation.validate_type_immutability(var_name, var_type)
101
101
 
102
102
  def process_annotation(self, cls : Type , # Process single annotation
@@ -22,7 +22,7 @@ class Type_Safe__Step__Set_Attr:
22
22
  else:
23
23
  value = self.resolve_value__from_origin(value)
24
24
 
25
- self.validate_literal_value(annotations, name, value) # Check Literal value constraints before generic type checking
25
+ self.validate_literal_value(_self, annotations, name, value) # Check Literal value constraints before generic type checking
26
26
 
27
27
  type_safe_validation.validate_type_compatibility(_self, annotations, name, value)
28
28
  return value
@@ -106,7 +106,7 @@ class Type_Safe__Step__Set_Attr:
106
106
  if name in immutable_vars:
107
107
  expected_type = immutable_vars[name]
108
108
  current_type = type if value is type else type(value)
109
- type_safe_validation.validate_if__types_are_compatible_for_assigment(name, current_type, expected_type)
109
+ type_safe_validation.validate_if__types_are_compatible_for_assigment(_self, name, current_type, expected_type)
110
110
  _super.__setattr__(name, value)
111
111
  return True
112
112
  return False
@@ -129,7 +129,7 @@ class Type_Safe__Step__Set_Attr:
129
129
 
130
130
  _super.__setattr__(name, value)
131
131
 
132
- def validate_literal_value(self, annotations, name, value): # Check if a value is valid for a Literal type annotation
132
+ def validate_literal_value(self, _self, annotations, name, value): # Check if a value is valid for a Literal type annotation
133
133
 
134
134
  annotation = annotations.get(name)
135
135
  if not annotation:
@@ -145,7 +145,7 @@ class Type_Safe__Step__Set_Attr:
145
145
  allowed_values = get_args(arg) # Found Literal inside Optional
146
146
  if value is not None and value not in allowed_values:
147
147
  allowed_str = ', '.join(repr(v) for v in allowed_values)
148
- raise ValueError(f"Invalid value for '{name}': must be one of [{allowed_str}], got {repr(value)}")
148
+ raise ValueError(f"On {_self.__class__.__name__}, invalid value for '{name}': must be one of [{allowed_str}], got {repr(value)}")
149
149
  return
150
150
 
151
151
 
@@ -153,7 +153,7 @@ class Type_Safe__Step__Set_Attr:
153
153
  allowed_values = get_args(annotation)
154
154
  if value not in allowed_values:
155
155
  allowed_str = ', '.join(repr(v) for v in allowed_values)
156
- raise ValueError(f"Invalid value for '{name}': must be one of [{allowed_str}], got {repr(value)}")
156
+ raise ValueError(f"On {_self.__class__.__name__}, invalid value for '{name}': must be one of [{allowed_str}], got {repr(value)}")
157
157
 
158
158
 
159
159
  type_safe_step_set_attr = Type_Safe__Step__Set_Attr()
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.87.0
1
+ v2.88.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.87.0
3
+ Version: 2.88.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  License: MIT
6
6
  Author: Dinis Cruz
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
21
21
 
22
22
  # OSBot-Utils
23
23
 
24
- ![Current Release](https://img.shields.io/badge/release-v2.87.0-blue)
24
+ ![Current Release](https://img.shields.io/badge/release-v2.88.0-blue)
25
25
  ![Python](https://img.shields.io/badge/python-3.8+-green)
26
26
  ![Type-Safe](https://img.shields.io/badge/Type--Safe-✓-brightgreen)
27
27
  ![Caching](https://img.shields.io/badge/Caching-Built--In-orange)
@@ -349,7 +349,7 @@ osbot_utils/testing/performance/models/Model__Performance_Measure__Result.py,sha
349
349
  osbot_utils/testing/performance/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
350
350
  osbot_utils/testing/test_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
351
351
  osbot_utils/testing/test_data/const__test__data__html.py,sha256=_DmA7OoCwvl1xxxn2aS8mfvf3Ct4bOt1KTUyTDqtwaQ,1718
352
- osbot_utils/type_safe/Type_Safe.py,sha256=WrsGJgD4iEoKN8z-ZU6RB78QcloLVxck-CB83f44yJw,6398
352
+ osbot_utils/type_safe/Type_Safe.py,sha256=2rlOJuB0fNiiefKqIKUw34vs1hGWms-Ah_SaIg7tj28,6427
353
353
  osbot_utils/type_safe/Type_Safe__Base.py,sha256=cui8fIzUGaPsb-fnANj8nw9cYrVikdx1XZ8in3Y_-QU,9174
354
354
  osbot_utils/type_safe/Type_Safe__Primitive.py,sha256=Eufm1CSenInqW8gAgULhUAXV_lMmA4UY4A5U9v8qmnU,4135
355
355
  osbot_utils/type_safe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -427,16 +427,16 @@ osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Convert.py,sha256=g2lo_11
427
427
  osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Json_Compressor.py,sha256=L5EiMPP-7vvzesW-Zs1YRPv1C544NiMTMag2saUnPrc,5522
428
428
  osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Json_Compressor__Type_Registry.py,sha256=wYOCg7F1nTrRn8HlnZvrs_8A8WL4gxRYRLnXZpGIiuk,1119
429
429
  osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Not_Cached.py,sha256=25FAl6SOLxdStco_rm9tgOYLfuKyBWheGdl7vVa56UU,800
430
- osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Raise_Exception.py,sha256=lEwW5bhOKnOB8KfuMkheLQy1Xb7iDtTOXIvActRDtD0,911
430
+ osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Raise_Exception.py,sha256=UCLEJpJPL4wnuX6f7YxawqArMtfWdLfuhFMfB7Z0yq4,1355
431
431
  osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Shared__Variables.py,sha256=SuZGl9LryQX6IpOE0I_lbzClT-h17UNylC__-M8ltTY,129
432
- osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Validation.py,sha256=cVfGNeZ7eriAghCpPTtS2bXqZT9GHLY9DK1uWMTSUdE,21124
432
+ osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Validation.py,sha256=tAH09G0b-xN3J2yNOcvHR03viM8zlMRBuuLQx3JY_yw,21249
433
433
  osbot_utils/type_safe/type_safe_core/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
434
- osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Class_Kwargs.py,sha256=BbMPfCv5-RUZzh-TbyLBvykXZkdkR91jCGJoZ4R697g,8237
434
+ osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Class_Kwargs.py,sha256=t3hsy_Q0eS_9hYsEd1_bhVvSybwcq26DKcjK8_11P9Q,8247
435
435
  osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
436
436
  osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Default_Value.py,sha256=mRu0yV3w7Ch1H8SOfXMRqMBp3ooY95yR_oni7JafJBc,4603
437
437
  osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__From_Json.py,sha256=QDVf-cN7aK8_xYdkHS74seSrMYyhurd_MEzgTlUyStg,15712
438
438
  osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Init.py,sha256=lZpQCCTNt6JcqyWwDoj-9Zgrq10vHXIUBh9lx37vRkE,4990
439
- osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Set_Attr.py,sha256=ywUYo97jcZkHZ7BJ7GTTuici2obz-Nwch4TcM6ilDcY,9237
439
+ osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Set_Attr.py,sha256=OLAzZ6FUfTYk4tqIRe_JGvBR_WZqPZFqM2aD_AMKb0c,9320
440
440
  osbot_utils/type_safe/type_safe_core/steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
441
441
  osbot_utils/type_safe/validators/Type_Safe__Validator.py,sha256=cJIPSBarjV716SZUOLvz7Mthjk-aUYKUQtRDtKUBmN4,779
442
442
  osbot_utils/type_safe/validators/Validator__Max.py,sha256=pCvYF5Jb_cBgn1ArGhf6FNUB-NGCXPq3D36oYDCyAzg,1275
@@ -470,8 +470,8 @@ osbot_utils/utils/Toml.py,sha256=grjWkVPIMVkawJ499FVIJKxQp8FJ2wcsd0Z3YIR4drM,114
470
470
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
471
471
  osbot_utils/utils/Zip.py,sha256=mG42lgTY0tnm14T3P1-DSAIZKkTiYoO3odZ1aOUdc1I,14394
472
472
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
473
- osbot_utils/version,sha256=XwHyoJ_wFA2bjrNtuxOF4NM6cnDdMz3jajvwUly7V7w,8
474
- osbot_utils-2.87.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
475
- osbot_utils-2.87.0.dist-info/METADATA,sha256=f7H-pt4SZ5tPhp3S_3fP5LXkSbiQnibM-NL8NbIzcVw,7918
476
- osbot_utils-2.87.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
477
- osbot_utils-2.87.0.dist-info/RECORD,,
473
+ osbot_utils/version,sha256=u1LBWyu3twx83JpD3wK_Gaq_Qp9K5LjWM2VKJa6aO50,8
474
+ osbot_utils-2.88.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
475
+ osbot_utils-2.88.0.dist-info/METADATA,sha256=nnRNyYqN_GhoIZJE0Al-lCnDdCNWQ3bB4dqbDIeoHhU,7918
476
+ osbot_utils-2.88.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
477
+ osbot_utils-2.88.0.dist-info/RECORD,,