Skip to content

Commit

Permalink
Meaningful __repr__ for objects
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Jul 21, 2023
1 parent 5a44505 commit 789ba54
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mwdblib/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ def last_seen(self) -> "datetime.datetime":
if "last_seen" not in self.data:
self._load()
return datetime.datetime.fromisoformat(self.data["last_seen"])

def __repr__(self) -> str:
return (
f"MWDBBlob(id={repr(self.id)}, name={repr(self.blob_name)}, "
f"type={repr(self.blob_type)})"
)
3 changes: 3 additions & 0 deletions mwdblib/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ def delete(self) -> None:
Deletes this comment
"""
self.api.delete("object/{}/comment/{}".format(self.parent.id, self.id))

def __repr__(self) -> str:
return f"MWDBComment(id={repr(self.id)}, author={repr(self.author)})"
6 changes: 6 additions & 0 deletions mwdblib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ def cfg(self) -> Dict[str, Any]:
.. seealso:: :py:attr:`config_dict`
"""
return self.config

def __repr__(self) -> str:
return (
f"MWDBConfig(id={repr(self.id)}, family={repr(self.family)}, "
f"type={repr(self.type)})"
)
6 changes: 6 additions & 0 deletions mwdblib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,3 +1053,9 @@ def upload_blob(
)
result = self.api.post("blob", json=params)
return MWDBBlob(self.api, result)

def __repr__(self) -> str:
return (
f"MWDB(api_url={repr(self.api.options.api_url)}, "
f"username={repr(self.api.logged_user)})"
)
3 changes: 3 additions & 0 deletions mwdblib/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ def download_legacy(self) -> bytes:
"/"
)[-1]
return cast(bytes, self.api.get("download/{}".format(token), raw=True))

def __repr__(self) -> str:
return f"MWDBFile(sha256={repr(self.id)}, name={repr(self.file_name)})"
3 changes: 3 additions & 0 deletions mwdblib/karton.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ def arguments(self) -> Dict[str, Any]:
@property
def processing_in(self) -> Dict[str, Any]:
return cast(Dict[str, Any], self.data["processing_in"])

def __repr__(self) -> str:
return f"MWDBKartonAnalysis(id={repr(self.id)})"

0 comments on commit 789ba54

Please sign in to comment.