Skip to content

Commit

Permalink
added methods Type_Safe.bytes and Json.json_to_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 3451b25 commit 95e940b
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion osbot_utils/base_classes/Type_Safe.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
from osbot_utils.utils.Dev import pprint
from osbot_utils.utils.Json import json_parse
from osbot_utils.utils.Json import json_parse, json_to_bytes
from osbot_utils.utils.Misc import list_set
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, \
@@ -230,9 +230,13 @@ def __schema__(cls):
# global methods added to any class that base classes this
# todo: see if there should be a prefix on these methods, to make it easier to spot them
# of if these are actually that useful that they should be added like this
def bytes(self):
return json_to_bytes(self.json())

def json(self):
return self.serialize_to_dict()


def merge_with(self, target):
original_attrs = {k: v for k, v in self.__dict__.items() if k not in target.__dict__} # Store the original attributes of self that should be retained.
self.__dict__ = target.__dict__ # Set the target's __dict__ to self, now self and target share the same __dict__.
1 change: 1 addition & 0 deletions osbot_utils/utils/Json.py
Original file line number Diff line number Diff line change
@@ -158,6 +158,7 @@ def json_save_tmp_file(python_object, pretty=True):
json_lines_loads = Json.loads_json_lines
json_parse = Json.loads
json_lines_parse = Json.loads_json_lines
json_to_bytes = json_dumps_to_bytes
json_to_str = json_dumps
json_round_trip = Json.round_trip
json_save = Json.save_file

0 comments on commit 95e940b

Please sign in to comment.