From be2b3ec1e81e4d82628fb2710b66c5abaeea9dfd Mon Sep 17 00:00:00 2001 From: Teknique Date: Sun, 23 Jul 2023 12:47:31 -0700 Subject: [PATCH] More helpful class reprs --- veilid-python/veilid/error.py | 4 ++++ veilid-python/veilid/types.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/veilid-python/veilid/error.py b/veilid-python/veilid/error.py index dfd7ff9a..17459fcd 100644 --- a/veilid-python/veilid/error.py +++ b/veilid-python/veilid/error.py @@ -13,6 +13,10 @@ class VeilidAPIError(Exception): def __init__(self, *args, **kwargs): super().__init__(self.label, *args, **kwargs) + def __str__(self) -> str: + args = [('label', self.label)] + sorted(vars(self).items()) + return " ".join(f"{key}={value!r}" for (key, value) in args) + @classmethod def from_json(cls, json: dict) -> Self: kind = json["kind"] diff --git a/veilid-python/veilid/types.py b/veilid-python/veilid/types.py index f2d254ec..a9a80587 100644 --- a/veilid-python/veilid/types.py +++ b/veilid-python/veilid/types.py @@ -351,6 +351,9 @@ class DHTRecordDescriptor: self.owner_secret = owner_secret self.schema = schema + def __repr__(self) -> str: + return f"<{self.__class__.__name__}(key={self.key!r})>" + @classmethod def from_json(cls, j: dict) -> Self: return cls( @@ -375,6 +378,9 @@ class ValueData: self.data = data self.writer = writer + def __repr__(self) -> str: + return f"<{self.__class__.__name__}(seq={self.seq!r}, data={self.data!r}, writer={self.writer!r})>" + def __lt__(self, other): if other is None: return True