osbot-utils 2.5.0__py3-none-any.whl → 2.6.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.
@@ -1,9 +1,9 @@
1
1
  import inspect # For function introspection
2
- from enum import Enum
3
- from typing import get_args, get_origin, Union, List, Any # For type hinting utilities
2
+ from enum import Enum
3
+ from typing import get_args, get_origin, Union, List, Any, Dict # For type hinting utilities
4
4
 
5
5
 
6
- class Type_Safe__Method: # Class to handle method type safety validation
6
+ class Type_Safe__Method: # Class to handle method type safety validation
7
7
  def __init__(self, func): # Initialize with function
8
8
  self.func = func # Store original function
9
9
  self.sig = inspect.signature(func) # Get function signature
@@ -88,8 +88,10 @@ class Type_Safe__Method:
88
88
  def is_union_type(self, origin_type: Any, is_optional: bool) -> bool: # Check if type is a Union
89
89
  return origin_type is Union and not is_optional # Must be Union but not Optional
90
90
 
91
- def validate_union_type(self, param_name: str, # Validate union type
92
- param_value: Any, expected_type: Any): # Union parameters
91
+ def validate_union_type(self, param_name : str,
92
+ param_value : Any,
93
+ expected_type: Any): # validate Union type parameters
94
+
93
95
  args_types = get_args(expected_type) # Get allowed types
94
96
  if not any(isinstance(param_value, arg_type) for arg_type in args_types): # Check if value matches any type
95
97
  raise ValueError(f"Parameter '{param_name}' expected one of types {args_types}, but got {type(param_value)}") # Raise error if no match
@@ -110,10 +112,37 @@ class Type_Safe__Method:
110
112
  except Exception: # Handle conversion failure
111
113
  pass # Continue without conversion
112
114
  return False # Return failure
113
- # Return failure
115
+ # Return failure
116
+
117
+ def validate_direct_type(self, param_name: str, param_value: Any, expected_type: Any):
118
+ if expected_type is Any: # Handle typing.Any which accepts everything
119
+ return True
120
+
121
+ if param_value is None: # Handle None value case
122
+ is_optional = self.is_optional_type(expected_type) # Check if type is optional
123
+ has_default = self.has_default_value(param_name) # Check if has default value
124
+ self.validate_none_value(param_name, is_optional, has_default) # Validate None value
114
125
 
115
- def validate_direct_type(self, param_name: str, # Validate direct type match
116
- param_value: Any, expected_type: Any): # Type parameters
117
- if expected_type is not Any:
118
- if not isinstance(param_value, expected_type): # Check type match
119
- raise ValueError(f"Parameter '{param_name}' expected type {expected_type}, but got {type(param_value)}") # Raise error if no match
126
+ origin = get_origin(expected_type)
127
+
128
+ if origin is Union: # If it's a Union type
129
+ return True # there is another check that confirms it: todo: confirm this
130
+
131
+ if origin is not None: # If it's a generic type (like Dict, List, etc)
132
+ if origin in (dict, Dict): # Special handling for Dict
133
+ if not isinstance(param_value, dict):
134
+ raise ValueError(f"Parameter '{param_name}' expected dict but got {type(param_value)}")
135
+ key_type, value_type = get_args(expected_type)
136
+ for k, v in param_value.items():
137
+ if not isinstance(k, key_type):
138
+ raise ValueError(f"Dict key '{k}' expected type {key_type}, but got {type(k)}")
139
+ if not isinstance(v, value_type):
140
+ raise ValueError(f"Dict value for key '{k}' expected type {value_type}, but got {type(v)}")
141
+ return True
142
+ base_type = origin
143
+ else:
144
+ base_type = expected_type
145
+
146
+ if not isinstance(param_value, base_type):
147
+ raise ValueError(f"Parameter '{param_name}' expected type {expected_type}, but got {type(param_value)}")
148
+ return True
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.5.0
1
+ v2.6.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.5.0
3
+ Version: 2.6.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  Home-page: https://github.com/owasp-sbot/OSBot-Utils
6
6
  License: MIT
@@ -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.5.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.6.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
 
@@ -281,7 +281,7 @@ osbot_utils/type_safe/Type_Safe.py,sha256=icn7r8mS1hkeo30uJ3NVJ7kms8P6MeHbA0ldz_
281
281
  osbot_utils/type_safe/Type_Safe__Base.py,sha256=mL8GMaR9tsaUfwk8d-8zp2g-A8kNKiN6kroEFaNvMOk,5518
282
282
  osbot_utils/type_safe/Type_Safe__Dict.py,sha256=I_Ac0JH-ahmQrkADFVyiobTlH1JI31MKHaNszQW4PBo,2396
283
283
  osbot_utils/type_safe/Type_Safe__List.py,sha256=SzSIBkwSOAEpW_V2qh4-f0YHzmgB0T8PczBLbDgZGvg,1340
284
- osbot_utils/type_safe/Type_Safe__Method.py,sha256=wn05pjmdnjhXVFIUaxm6YfWJZGoTzs-IhJ534JKFiV0,10970
284
+ osbot_utils/type_safe/Type_Safe__Method.py,sha256=LOG2sqQyKBNNEiJxk_jngH6IWvpyVueouAzNTlj-_pY,12676
285
285
  osbot_utils/type_safe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
286
286
  osbot_utils/type_safe/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
287
287
  osbot_utils/type_safe/decorators/type_safe.py,sha256=ERFfJuAIo5qLp03YEDu2zu5wxu65OhR7hOybwuTfLlc,1006
@@ -317,8 +317,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
317
317
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
318
318
  osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
319
319
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
320
- osbot_utils/version,sha256=ry5x0al4PtQq-0dv-mNU4Gk_sTAHYopdKOQmdWyn-ZE,7
321
- osbot_utils-2.5.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
322
- osbot_utils-2.5.0.dist-info/METADATA,sha256=Ow8znW_Olql05eKUGfwxkJDw5XMf0o_wwXjdS7J2In0,1315
323
- osbot_utils-2.5.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
324
- osbot_utils-2.5.0.dist-info/RECORD,,
320
+ osbot_utils/version,sha256=dngZhSwLPfXtj92IQJKmOr3AcG9xlHjFvq5HyQEcl_s,7
321
+ osbot_utils-2.6.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
322
+ osbot_utils-2.6.0.dist-info/METADATA,sha256=I0JH-4t4kPo3RIKeAMFjQp616AUaaXsWBjGkzq0oc5c,1315
323
+ osbot_utils-2.6.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
324
+ osbot_utils-2.6.0.dist-info/RECORD,,