osbot-utils 2.7.0__py3-none-any.whl → 2.8.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,6 +1,6 @@
1
1
  # todo: find a way to add these documentations strings to a separate location so that
2
2
  # the data is available in IDE's code complete
3
-
3
+ import inspect
4
4
  import sys
5
5
  import types
6
6
  from osbot_utils.utils.Objects import default_value # todo: remove test mocking requirement for this to be here (instead of on the respective method)
@@ -198,6 +198,15 @@ class Type_Safe:
198
198
  import typing
199
199
  from osbot_utils.type_safe.Type_Safe__List import Type_Safe__List
200
200
  from osbot_utils.type_safe.Type_Safe__Dict import Type_Safe__Dict
201
+ if get_origin(var_type) is type: # Special handling for Type[T] # todo: reuse the get_origin value
202
+ type_args = get_args(var_type)
203
+ if type_args:
204
+ if isinstance(type_args[0], ForwardRef):
205
+ forward_name = type_args[0].__forward_arg__
206
+ for base_cls in inspect.getmro(cls):
207
+ if base_cls.__name__ == forward_name:
208
+ return cls # note: in this case we return the cls, and not the base_cls (which makes sense since this happens when the cls class uses base_cls as base, which has a ForwardRef to base_cls )
209
+ return type_args[0] # Return the actual type as the default value
201
210
 
202
211
  if var_type is typing.Set: # todo: refactor the dict, set and list logic, since they are 90% the same
203
212
  return set()
@@ -469,9 +469,12 @@ def value_type_matches_obj_annotation_for_attr(target, attr_name, value):
469
469
  origin_attr_type = get_origin(attr_type) # to handle when type definition contains a generic
470
470
  if origin_attr_type is type: # Add handling for Type[T]
471
471
  type_arg = get_args(attr_type)[0] # Get T from Type[T]
472
+ if type_arg == value:
473
+ return True
472
474
  if isinstance(type_arg, (str, ForwardRef)): # Handle forward reference
473
475
  type_arg = target.__class__ # If it's a forward reference, the target class should be the containing class
474
476
  return isinstance(value, type) and issubclass(value, type_arg) # Check that value is a type and is subclass of type_arg
477
+
475
478
  if origin_attr_type is Annotated: # if the type is Annotated
476
479
  args = get_args(attr_type)
477
480
  origin_attr_type = args[0]
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v2.7.0
1
+ v2.8.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: osbot_utils
3
- Version: 2.7.0
3
+ Version: 2.8.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.7.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v2.8.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
 
@@ -277,7 +277,7 @@ osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=ibDIWt3K4CX558PbkLbX3InHyWYZcwQ
277
277
  osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
278
278
  osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
279
279
  osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
280
- osbot_utils/type_safe/Type_Safe.py,sha256=NwniGTMB9La3Sbo08FkPn01ka9h70n8jTRcqtqSrmi4,30467
280
+ osbot_utils/type_safe/Type_Safe.py,sha256=RSifqVaTJSGNJZZZ76c_2snwaTk4wA0vNyfRMEbM0S8,31301
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
@@ -305,7 +305,7 @@ osbot_utils/utils/Json.py,sha256=0t7Hwefx8bg4JiZVr-xIbWP3BAk6_ZsnY7iV5pnRLDQ,713
305
305
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
306
306
  osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
307
307
  osbot_utils/utils/Misc.py,sha256=H_xexJgiTxB3jDeDiW8efGQbO0Zuy8MM0iQ7qXC92JI,17363
308
- osbot_utils/utils/Objects.py,sha256=KN04fgKTlPtKr1d84ESDNlYMQikunyWJ3-I2VKZ8jjw,23661
308
+ osbot_utils/utils/Objects.py,sha256=3GHd0MzqXgE-_mTS58GIgmIUy2SY4lb6V99EtkgRUc0,23724
309
309
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
310
310
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
311
311
  osbot_utils/utils/Python_Logger.py,sha256=M9Oi62LxfnRSlCN8GhaiwiBINvcSdGy39FCWjyDD-Xg,12792
@@ -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=EtyVXU03AffYJg9oYhRGCGg4FoQy8uTssAJDNu9cIQY,7
321
- osbot_utils-2.7.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
322
- osbot_utils-2.7.0.dist-info/METADATA,sha256=EwDB5K1xIrl97T8tWVAoGIdK8XOKdyQ4uqe9ZR_qI6Y,1315
323
- osbot_utils-2.7.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
324
- osbot_utils-2.7.0.dist-info/RECORD,,
320
+ osbot_utils/version,sha256=Vt_dE-36EgGrcGxt9_UkufT4EOFOMX_R0CvxP7EWs3Q,7
321
+ osbot_utils-2.8.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
322
+ osbot_utils-2.8.0.dist-info/METADATA,sha256=GVsY5k5bjFoFhai2ON3ptyZOn7YvAyJVqFTBCRvf0lk,1315
323
+ osbot_utils-2.8.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
324
+ osbot_utils-2.8.0.dist-info/RECORD,,