Skip to content

Commit

Permalink
Merge dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 21, 2024
2 parents 8b40cd9 + ba8d75e commit ef324af
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

Powerful Python util methods and classes that simplify common apis and tasks.

![Current Release](https://img.shields.io/badge/release-v1.65.0-blue)
![Current Release](https://img.shields.io/badge/release-v1.65.2-blue)
[![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)


6 changes: 3 additions & 3 deletions osbot_utils/base_classes/Type_Safe.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
obj_is_type_union_compatible, value_type_matches_obj_annotation_for_union_attr, \
convert_dict_to_value_from_obj_annotation, dict_to_obj, convert_str_to_value_from_obj_annotation
convert_dict_to_value_from_obj_annotation, dict_to_obj, convert_to_value_from_obj_annotation

# Backport implementations of get_origin and get_args for Python 3.7
if sys.version_info < (3, 8): # pragma: no cover
@@ -99,8 +99,8 @@ def __setattr__(self, name, value):
if value is not None:
if type(value) is dict:
value = convert_dict_to_value_from_obj_annotation(self, name, value)
if type(value) is str:
value = convert_str_to_value_from_obj_annotation (self, name, value)
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)
value = convert_to_value_from_obj_annotation (self, name, value)
check_1 = value_type_matches_obj_annotation_for_attr (self, name, value)
check_2 = value_type_matches_obj_annotation_for_union_attr(self, name, value)
if (check_1 is False and check_2 is None or
9 changes: 6 additions & 3 deletions osbot_utils/utils/Objects.py
Original file line number Diff line number Diff line change
@@ -8,10 +8,13 @@
from collections.abc import Mapping
from typing import Union
from types import SimpleNamespace
from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
from osbot_utils.helpers.Random_Guid import Random_Guid
from osbot_utils.utils.Misc import list_set
from osbot_utils.utils.Str import str_unicode_escape, str_max_width

TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES = [Random_Guid, Timestamp_Now]

# Backport implementations of get_origin and get_args for Python 3.7
if sys.version_info < (3, 8):
def get_origin(tp):
@@ -105,14 +108,14 @@ def convert_dict_to_value_from_obj_annotation(target, attr_name, value):
return attribute_annotation(**value)
return value

def convert_str_to_value_from_obj_annotation(target, attr_name, value): # todo: see the side effects of doing this for all strings
def convert_to_value_from_obj_annotation(target, attr_name, value): # todo: see the side effects of doing this for all ints and floats
if target is not None and attr_name is not None:
if hasattr(target, '__annotations__'):
obj_annotations = target.__annotations__
if hasattr(obj_annotations,'get'):
attribute_annotation = obj_annotations.get(attr_name)
if 'str' in base_classes_names(attribute_annotation): # todo: figure out a better way to handle these special type casting (used for example by Random_Guid)
if attribute_annotation == Random_Guid: # and add support for other types like int (which is used my Timestamp_Now)
if attribute_annotation:
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
return attribute_annotation(value)
return value

2 changes: 1 addition & 1 deletion osbot_utils/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.65.0
v1.65.2
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "osbot_utils"
version = "v1.65.0"
version = "v1.65.2"
description = "OWASP Security Bot - Utils"
authors = ["Dinis Cruz <[email protected]>"]
license = "MIT"
2 changes: 1 addition & 1 deletion tests/unit/helpers/trace/test_Trace_Call.py
Original file line number Diff line number Diff line change
@@ -277,7 +277,7 @@ def test__trace_up_to_a_level(self):
'\x1b[1m📦 Trace Session\x1b[0m' ,
'\x1b[1m│ ├── 🔗️ Python_Logger.__init__\x1b[0m' ,
'\x1b[1m│ │ ├── 🧩️ Python_Logger_Config.__init__\x1b[0m',
'\x1b[1m│ │ ├── 🧩️ convert_str_to_value_from_obj_annotation\x1b[0m',
'\x1b[1m│ │ ├── 🧩️ convert_to_value_from_obj_annotation\x1b[0m',
'\x1b[1m│ │ ├── 🧩️ set_logger_name\x1b[0m' ,
'\x1b[1m│ │ ├── 🧩️ set_config\x1b[0m' ,
'\x1b[1m│ │ └── 🧩️ setup\x1b[0m' ,

0 comments on commit ef324af

Please sign in to comment.