Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Fix the method overloading issues in python
Browse files Browse the repository at this point in the history
  • Loading branch information
Trickybrain committed Mar 28, 2024
1 parent 0612d8d commit 0e340ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 9 additions & 6 deletions python/selfie-lib/selfie_lib/Snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ def __str__(self):
return f"[{self._subject} {self._facet_data}]"

@staticmethod
def of(binary):
return Snapshot(SnapshotValue.of(binary), {})

@staticmethod
def of(string):
return Snapshot(SnapshotValue.of(string), {})
def of(data):
if isinstance(data, bytes):
# Handling binary data
return Snapshot(SnapshotValue.of(data), {})
elif isinstance(data, str):
# Handling string data
return Snapshot(SnapshotValue.of(data), {})
else:
raise TypeError("Data must be either binary or string")

@staticmethod
def of_entries(entries):
Expand Down
14 changes: 8 additions & 6 deletions python/selfie-lib/selfie_lib/SnapshotValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def value_string(self) -> str:
pass

@staticmethod
def of(value: Union[bytes, str]) -> "SnapshotValue":
if isinstance(value, bytes):
return SnapshotValueBinary(value)
elif isinstance(value, str):
return SnapshotValueString(unix_newlines(value))
def of(cls, data):
if isinstance(data, bytes):
return cls(SnapshotValue.of(data), {})
elif isinstance(data, str):
return cls(SnapshotValue.of(data), {})
elif isinstance(data, SnapshotValue):
return cls(data, {})
else:
raise TypeError("Value must be either bytes or str")
raise TypeError("Unsupported type for Snapshot creation")


class SnapshotValueBinary(SnapshotValue):
Expand Down

0 comments on commit 0e340ed

Please sign in to comment.