osbot-utils 1.64.0__py3-none-any.whl → 1.66.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.
@@ -16,10 +16,10 @@ from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
16
16
  from osbot_utils.utils.Dev import pprint
17
17
  from osbot_utils.utils.Json import json_parse
18
18
  from osbot_utils.utils.Misc import list_set
19
- from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
19
+ from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
20
20
  raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
21
21
  obj_is_type_union_compatible, value_type_matches_obj_annotation_for_union_attr, \
22
- convert_dict_to_value_from_obj_annotation, dict_to_obj
22
+ convert_dict_to_value_from_obj_annotation, dict_to_obj, convert_to_value_from_obj_annotation
23
23
 
24
24
  # Backport implementations of get_origin and get_args for Python 3.7
25
25
  if sys.version_info < (3, 8): # pragma: no cover
@@ -99,6 +99,8 @@ class Type_Safe:
99
99
  if value is not None:
100
100
  if type(value) is dict:
101
101
  value = convert_dict_to_value_from_obj_annotation(self, name, value)
102
+ if type(value) in [int, str]: # for now only a small number of str and int classes are supported (until we understand the full implications of this)
103
+ value = convert_to_value_from_obj_annotation (self, name, value)
102
104
  check_1 = value_type_matches_obj_annotation_for_attr (self, name, value)
103
105
  check_2 = value_type_matches_obj_annotation_for_union_attr(self, name, value)
104
106
  if (check_1 is False and check_2 is None or
@@ -5,12 +5,15 @@ import pickle
5
5
  import sys
6
6
  import types
7
7
  import typing
8
- from collections.abc import Mapping
8
+ from collections.abc import Mapping
9
+ from typing import Union
10
+ from types import SimpleNamespace
11
+ from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
12
+ from osbot_utils.helpers.Random_Guid import Random_Guid
13
+ from osbot_utils.utils.Misc import list_set
14
+ from osbot_utils.utils.Str import str_unicode_escape, str_max_width
9
15
 
10
- from typing import Union
11
- from types import SimpleNamespace
12
- from osbot_utils.utils.Misc import list_set
13
- from osbot_utils.utils.Str import str_unicode_escape, str_max_width
16
+ TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES = [Random_Guid, Timestamp_Now]
14
17
 
15
18
  # Backport implementations of get_origin and get_args for Python 3.7
16
19
  if sys.version_info < (3, 8):
@@ -95,7 +98,7 @@ def class_full_name(target):
95
98
  type_name = type_target.__name__
96
99
  return f'{type_module}.{type_name}'
97
100
 
98
- def convert_dict_to_value_from_obj_annotation(target, attr_name, value):
101
+ def convert_dict_to_value_from_obj_annotation(target, attr_name, value): # todo: refactor this with code from convert_str_to_value_from_obj_annotation since it is mostly the same
99
102
  if target is not None and attr_name is not None:
100
103
  if hasattr(target, '__annotations__'):
101
104
  obj_annotations = target.__annotations__
@@ -105,6 +108,17 @@ def convert_dict_to_value_from_obj_annotation(target, attr_name, value):
105
108
  return attribute_annotation(**value)
106
109
  return value
107
110
 
111
+ def convert_to_value_from_obj_annotation(target, attr_name, value): # todo: see the side effects of doing this for all ints and floats
112
+ if target is not None and attr_name is not None:
113
+ if hasattr(target, '__annotations__'):
114
+ obj_annotations = target.__annotations__
115
+ if hasattr(obj_annotations,'get'):
116
+ attribute_annotation = obj_annotations.get(attr_name)
117
+ if attribute_annotation:
118
+ if attribute_annotation in TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES: # for now hard-coding this to just these types until we understand the side effects
119
+ return attribute_annotation(value)
120
+ return value
121
+
108
122
 
109
123
  def default_value(target : type):
110
124
  try:
@@ -382,7 +396,6 @@ def value_type_matches_obj_annotation_for_attr(target, attr_name, value):
382
396
  return True
383
397
  if are_types_magic_mock(source_type=value_type, target_type=attr_type):
384
398
  return True
385
-
386
399
  return value_type is attr_type
387
400
  return None
388
401
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.64.0
1
+ v1.66.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.64.0
3
+ Version: 1.66.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-v1.64.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v1.66.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
 
@@ -2,7 +2,7 @@ osbot_utils/__init__.py,sha256=DdJDmQc9zbQUlPVyTJOww6Ixrn9n4bD3ami5ItQfzJI,16
2
2
  osbot_utils/base_classes/Cache_Pickle.py,sha256=kPCwrgUbf_dEdxUz7vW1GuvIPwlNXxuRhb-H3AbSpII,5884
3
3
  osbot_utils/base_classes/Kwargs_To_Disk.py,sha256=HHoy05NC_w35WcT-OnSKoSIV_cLqaU9rdjH0_KNTM0E,1096
4
4
  osbot_utils/base_classes/Kwargs_To_Self.py,sha256=weFNsBfBNV9W_qBkN-IdBD4yYcJV_zgTxBRO-ZlcPS4,141
5
- osbot_utils/base_classes/Type_Safe.py,sha256=eWdLnt-vRqr6bX1TR3tINSqm2KeVXQSzQs6pxq0Ep5I,18476
5
+ osbot_utils/base_classes/Type_Safe.py,sha256=N1RMyDEA9YFI5MciixobxM0ZjbEQpPtj8XzmzTrPTls,18789
6
6
  osbot_utils/base_classes/Type_Safe__List.py,sha256=-80C9OhsK6iDR2dAG8yNLAZV0qg5x3faqvSUigFCMJw,517
7
7
  osbot_utils/base_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  osbot_utils/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -293,7 +293,7 @@ osbot_utils/utils/Json.py,sha256=yIT2hUI23gYd24Uf3LCjqPNV67zS46rYZftcCM3jw-Q,649
293
293
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
294
294
  osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
295
295
  osbot_utils/utils/Misc.py,sha256=4MkG2BE1VzZfV4KPzYZ4jVAoUwoA3pTTVPi609ldLGA,16961
296
- osbot_utils/utils/Objects.py,sha256=_BWr7KA8Xzzxu6fyxHSqDqDM1Pkyr5IZUFo_hMf7oTo,17612
296
+ osbot_utils/utils/Objects.py,sha256=sYBpcKfvG3QRE5NSet_9e9MqOhRvKGowuWkGDtijY1g,18724
297
297
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
298
298
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
299
299
  osbot_utils/utils/Python_Logger.py,sha256=tx8N6wRKL3RDHboDRKZn8SirSJdSAE9cACyJkxrThZ8,12792
@@ -305,8 +305,8 @@ osbot_utils/utils/Toml.py,sha256=SD6IA4-mrtoBXcI0dIGKV9POMQNd6WYKvmDQq7GQ6ZQ,143
305
305
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
306
306
  osbot_utils/utils/Zip.py,sha256=G6Hk_hDcm9yvWzhTKzhT0R_6f0NBIAchHqMxGb3kfh4,14037
307
307
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
308
- osbot_utils/version,sha256=Sb9LIFVVDPJapRKOM9P5OAlLpvoTKm6KXqS8_LOGd3k,8
309
- osbot_utils-1.64.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
- osbot_utils-1.64.0.dist-info/METADATA,sha256=kAPJmBcqPABY3iT_RLZwS5OUbV7PqHKiAvkkCJOZy8c,1317
311
- osbot_utils-1.64.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
- osbot_utils-1.64.0.dist-info/RECORD,,
308
+ osbot_utils/version,sha256=1QcmI8mVRJJdlWulkPzEykBmlNbrD6QZ-4jQHNIZtDc,8
309
+ osbot_utils-1.66.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
+ osbot_utils-1.66.0.dist-info/METADATA,sha256=IlgcQwbhyJQ9y7RWr1xQVk93pvICSope8bUxaWV2bdM,1317
311
+ osbot_utils-1.66.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
+ osbot_utils-1.66.0.dist-info/RECORD,,