osbot-utils 2.2.0__py3-none-any.whl → 2.3.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,15 +1,22 @@
1
1
  import inspect # For function introspection
2
2
  from enum import Enum
3
- from typing import get_args, get_origin, Optional, Union, List, Any, Dict # For type hinting utilities
3
+ from typing import get_args, get_origin, Union, List, Any # For type hinting utilities
4
4
 
5
5
 
6
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
10
- self.annotations = func.__annotations__ # Get type annotations
10
+ self.annotations = func.__annotations__ # Get function annotations
11
+
12
+ def check_for_any_use(self):
13
+ for param_name, type_hint in self.annotations.items():
14
+ if type_hint is any: # Detect incorrect usage of lowercase any
15
+ raise ValueError(f"Parameter '{param_name}' uses lowercase 'any' instead of 'Any' from typing module. "
16
+ f"Please use 'from typing import Any' and annotate as '{param_name}: Any'")
11
17
 
12
18
  def handle_type_safety(self, args: tuple, kwargs: dict): # Main method to handle type safety
19
+ self.check_for_any_use()
13
20
  bound_args = self.bind_args(args, kwargs) # Bind arguments to parameters
14
21
  for param_name, param_value in bound_args.arguments.items(): # Iterate through arguments
15
22
  if param_name != 'self': # Skip self parameter
@@ -107,5 +114,6 @@ class Type_Safe_Method:
107
114
 
108
115
  def validate_direct_type(self, param_name: str, # Validate direct type match
109
116
  param_value: Any, expected_type: Any): # Type parameters
110
- if not isinstance(param_value, expected_type): # Check type match
111
- raise ValueError(f"Parameter '{param_name}' expected type {expected_type}, but got {type(param_value)}") # Raise error if no match
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
File without changes
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.2.0
1
+ v2.3.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.2.0
3
+ Version: 2.3.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.2.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.3.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
 
@@ -29,7 +29,6 @@ osbot_utils/decorators/methods/function_type_check.py,sha256=o8Je6k-tXd3UmbgVL0g
29
29
  osbot_utils/decorators/methods/obj_as_context.py,sha256=59JgxUvEruh_4ROoWHXK22Jv8C4_E5mSxb4aG3JbL50,104
30
30
  osbot_utils/decorators/methods/remove_return_value.py,sha256=EerRwBFDJ3ICKA0BrNzelRECb3n2NUMoFzcn0rQyCUY,1162
31
31
  osbot_utils/decorators/methods/required_fields.py,sha256=PZd9LKd4qBeqxgP9FgTtLNNJ0coZx99hFJyNEKmF1K0,783
32
- osbot_utils/decorators/methods/type_safe.py,sha256=yK1td-9WHFj2pe4dvBtw1cjYOE6z6-VnG5DCStGCO1c,1003
33
32
  osbot_utils/fluent/Fluent_Dict.py,sha256=nZ2z91s39sU2a-TLYpBirRoWgDXHrs0tQ9Bi_ZdKeW0,481
34
33
  osbot_utils/fluent/Fluent_List.py,sha256=PfDDC9sm16CFnNQ8gkhCEsmKcZp8iyQ0YBpSHvYssG8,1089
35
34
  osbot_utils/fluent/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
@@ -279,12 +278,14 @@ osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq
279
278
  osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
280
279
  osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
281
280
  osbot_utils/type_safe/Type_Safe.py,sha256=irrNiwWQHV4eP2dq9aKYDIETsG375U9U055YPZX1uQw,29658
282
- osbot_utils/type_safe/Type_Safe_Method.py,sha256=8E88of__An9_ZhJKz6Kp22C1mb9WLED0jWNLOII3fJs,10489
281
+ osbot_utils/type_safe/Type_Safe_Method.py,sha256=JLB7NkeuY4x_lIWJyvG1bDApCM_VyAQqrzQXhH7Z-8A,10969
283
282
  osbot_utils/type_safe/Type_Safe__Base.py,sha256=mL8GMaR9tsaUfwk8d-8zp2g-A8kNKiN6kroEFaNvMOk,5518
284
283
  osbot_utils/type_safe/Type_Safe__Dict.py,sha256=I_Ac0JH-ahmQrkADFVyiobTlH1JI31MKHaNszQW4PBo,2396
285
284
  osbot_utils/type_safe/Type_Safe__List.py,sha256=SzSIBkwSOAEpW_V2qh4-f0YHzmgB0T8PczBLbDgZGvg,1340
286
285
  osbot_utils/type_safe/Type_Safe__Validator.py,sha256=cJIPSBarjV716SZUOLvz7Mthjk-aUYKUQtRDtKUBmN4,779
287
286
  osbot_utils/type_safe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
287
+ osbot_utils/type_safe/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
288
+ osbot_utils/type_safe/decorators/type_safe.py,sha256=yK1td-9WHFj2pe4dvBtw1cjYOE6z6-VnG5DCStGCO1c,1003
288
289
  osbot_utils/type_safe/validators/Validator__Max.py,sha256=ctsMADDqq9l9mxwedrOfI9Dg53nPxCsluB0cO8C6bT4,1264
289
290
  osbot_utils/type_safe/validators/Validator__Min.py,sha256=FfVoErZcibqYXvnH-Nl9c2pfPSKFH-CgAhUVBYsxVrc,1970
290
291
  osbot_utils/type_safe/validators/Validator__One_Of.py,sha256=RvEYjf2zT06LVucZeNhzFqTZOh-Bs-C9UNjXd_YLWa8,670
@@ -316,8 +317,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
316
317
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
317
318
  osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
318
319
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
319
- osbot_utils/version,sha256=uVurYQGLXTbYEagaxFAAZWDtcu72lhVJSfloDcK8tAU,7
320
- osbot_utils-2.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
321
- osbot_utils-2.2.0.dist-info/METADATA,sha256=k3jcHtdqYaJdLQDq7UJ_l2cIy0O3V6yj7rDUwkz54KE,1315
322
- osbot_utils-2.2.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
323
- osbot_utils-2.2.0.dist-info/RECORD,,
320
+ osbot_utils/version,sha256=B-GHcA-4RPUOEZ4BIL3emPJuZ5J9E1aQPTmIXKecyHE,7
321
+ osbot_utils-2.3.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
322
+ osbot_utils-2.3.0.dist-info/METADATA,sha256=_sYtNzPStrMRoLTa5C1PaRTfEzeeOV7SeccUXx9GAFo,1315
323
+ osbot_utils-2.3.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
324
+ osbot_utils-2.3.0.dist-info/RECORD,,