osbot-utils 2.81.0__py3-none-any.whl → 2.82.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.
- osbot_utils/type_safe/type_safe_core/methods/Type_Safe__Method.py +47 -17
- osbot_utils/version +1 -1
- {osbot_utils-2.81.0.dist-info → osbot_utils-2.82.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.81.0.dist-info → osbot_utils-2.82.0.dist-info}/RECORD +6 -6
- {osbot_utils-2.81.0.dist-info → osbot_utils-2.82.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.81.0.dist-info → osbot_utils-2.82.0.dist-info}/WHEEL +0 -0
@@ -2,6 +2,7 @@ import collections
|
|
2
2
|
import inspect # For function introspection
|
3
3
|
from enum import Enum
|
4
4
|
from typing import get_args, get_origin, Union, List, Any, Dict # For type hinting utilities
|
5
|
+
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
|
5
6
|
from osbot_utils.type_safe.type_safe_core.shared.Type_Safe__Shared__Variables import IMMUTABLE_TYPES
|
6
7
|
|
7
8
|
|
@@ -18,24 +19,53 @@ class Type_Safe__Method:
|
|
18
19
|
raise ValueError(f"Parameter '{param_name}' uses lowercase 'any' instead of 'Any' from typing module. "
|
19
20
|
f"Please use 'from typing import Any' and annotate as '{param_name}: Any'")
|
20
21
|
|
21
|
-
def
|
22
|
+
def convert_primitive_parameters(self, bound_args): # Convert parameters to Type_Safe__Primitive types where applicable
|
23
|
+
|
24
|
+
for param_name, param_value in bound_args.arguments.items():
|
25
|
+
if param_name == 'self' or param_name not in self.annotations:
|
26
|
+
continue
|
27
|
+
|
28
|
+
expected_type = self.annotations[param_name]
|
29
|
+
|
30
|
+
if not (isinstance(expected_type, type) and issubclass(expected_type, Type_Safe__Primitive)): # Check if expected type is a Type_Safe__Primitive subclass
|
31
|
+
continue
|
32
|
+
|
33
|
+
primitive_base = expected_type.__primitive_base__ # Try direct conversion for common cases
|
34
|
+
|
35
|
+
if primitive_base in (int, float) and isinstance(param_value, str): # Handle string to int/float conversion
|
36
|
+
try:
|
37
|
+
bound_args.arguments[param_name] = expected_type(param_value)
|
38
|
+
continue
|
39
|
+
except (ValueError, TypeError):
|
40
|
+
pass # Let normal validation handle the error
|
41
|
+
|
42
|
+
if primitive_base and isinstance(param_value, primitive_base): # Handle values that match the primitive base type
|
43
|
+
try:
|
44
|
+
bound_args.arguments[param_name] = expected_type(param_value)
|
45
|
+
except (ValueError, TypeError):
|
46
|
+
pass # Let normal validation handle the error
|
47
|
+
|
48
|
+
def handle_type_safety(self, args: tuple, kwargs: dict): # Main method to handle type safety
|
22
49
|
self.check_for_any_use()
|
23
|
-
bound_args = self.bind_args(args, kwargs)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
bound_args
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
50
|
+
bound_args = self.bind_args(args, kwargs) # Bind arguments to parameters
|
51
|
+
|
52
|
+
self.convert_primitive_parameters(bound_args) # Pre-process primitive type conversions
|
53
|
+
|
54
|
+
for param_name, param_value in bound_args.arguments.items(): # Iterate through arguments
|
55
|
+
if param_name != 'self': # Skip self parameter
|
56
|
+
self.validate_parameter(param_name, param_value, bound_args) # Validate each parameter
|
57
|
+
return bound_args # Return bound arguments
|
58
|
+
|
59
|
+
def bind_args(self, args: tuple, kwargs: dict): # Bind args to parameters
|
60
|
+
bound_args = self.sig.bind(*args, **kwargs) # Bind arguments to signature
|
61
|
+
bound_args.apply_defaults() # Apply default values
|
62
|
+
return bound_args # Return bound arguments
|
63
|
+
|
64
|
+
def validate_parameter(self, param_name: str, param_value: Any, bound_args): # Validate a single parameter
|
65
|
+
self.validate_immutable_parameter(param_name, param_value) # Validata the param_value (make sure if it set it is on of IMMUTABLE_TYPES)
|
66
|
+
if param_name in self.annotations: # Check if parameter is annotated
|
67
|
+
expected_type = self.annotations[param_name] # Get expected type
|
68
|
+
self.check_parameter_value(param_name, param_value, expected_type, bound_args) # Check value against type
|
39
69
|
|
40
70
|
def validate_immutable_parameter(self, param_name, param_value):
|
41
71
|
param = self.sig.parameters.get(param_name) # Check if this is a default value from a mutable type
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.82.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.82.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
|
-

|
25
25
|

|
26
26
|

|
27
27
|

|
@@ -417,7 +417,7 @@ osbot_utils/type_safe/type_safe_core/collections/Type_Safe__Tuple.py,sha256=Kx7C
|
|
417
417
|
osbot_utils/type_safe/type_safe_core/collections/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
418
418
|
osbot_utils/type_safe/type_safe_core/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
419
419
|
osbot_utils/type_safe/type_safe_core/decorators/type_safe.py,sha256=wOTMvZBl5hWMz-HuIRZpPBGN0oSbXWd9wH5xxZkfLlA,1796
|
420
|
-
osbot_utils/type_safe/type_safe_core/methods/Type_Safe__Method.py,sha256=
|
420
|
+
osbot_utils/type_safe/type_safe_core/methods/Type_Safe__Method.py,sha256=2xW4x3Hy_g3-Fs5rqyOWPHsmb8pBIqMG1iRe0qjjKW0,22154
|
421
421
|
osbot_utils/type_safe/type_safe_core/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
422
422
|
osbot_utils/type_safe/type_safe_core/methods/type_safe_property.py,sha256=DcJkOIs6swJtkglsZVKLyFSczCGSJISOVwAmvjCOQvo,1425
|
423
423
|
osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Annotations.py,sha256=kabSiRPYPjpMBJxfjDB5AFRTx-hX17tOznZAd_qQID4,1147
|
@@ -469,8 +469,8 @@ osbot_utils/utils/Toml.py,sha256=grjWkVPIMVkawJ499FVIJKxQp8FJ2wcsd0Z3YIR4drM,114
|
|
469
469
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
470
470
|
osbot_utils/utils/Zip.py,sha256=mG42lgTY0tnm14T3P1-DSAIZKkTiYoO3odZ1aOUdc1I,14394
|
471
471
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
472
|
-
osbot_utils/version,sha256=
|
473
|
-
osbot_utils-2.
|
474
|
-
osbot_utils-2.
|
475
|
-
osbot_utils-2.
|
476
|
-
osbot_utils-2.
|
472
|
+
osbot_utils/version,sha256=qTe6foGALmPxx0zKmfZb_cxkz5FH_-oA-y4_stF2cqY,8
|
473
|
+
osbot_utils-2.82.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
474
|
+
osbot_utils-2.82.0.dist-info/METADATA,sha256=8Ugc0xBnuAYes9fAMJtnLyfCFxvsYqIzgloK_mEaN00,7918
|
475
|
+
osbot_utils-2.82.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
476
|
+
osbot_utils-2.82.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|