From 9e03d00ae77440bb817626a6b3eb936908adb40d Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 13 Aug 2024 15:38:52 +0700 Subject: [PATCH 1/4] [syft/dicttuple] handle `repr_html` when there are no instances of the super class, e.g. Dataset --- packages/syft/src/syft/service/worker/worker_pool.py | 2 +- packages/syft/src/syft/types/dicttuple.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/worker/worker_pool.py b/packages/syft/src/syft/service/worker/worker_pool.py index fd085c3de57..e4aa49417c1 100644 --- a/packages/syft/src/syft/service/worker/worker_pool.py +++ b/packages/syft/src/syft/service/worker/worker_pool.py @@ -210,7 +210,7 @@ def _coll_repr_(self) -> dict[str, Any]: "Created at": str(self.created_at), } - def _repr_html_(self) -> Any: + def _repr_html_(self) -> str: return f"""

{self.name}

diff --git a/packages/syft/src/syft/types/dicttuple.py b/packages/syft/src/syft/types/dicttuple.py index 4a019052c09..7b357fdb2e3 100644 --- a/packages/syft/src/syft/types/dicttuple.py +++ b/packages/syft/src/syft/types/dicttuple.py @@ -238,6 +238,14 @@ def __getitem__(self, __key: _KT | slice | SupportsIndex, /) -> _VT | Self: def __repr__(self) -> str: return f"{self.__class__.__qualname__}{super().__repr__()}" + def _repr_html_(self) -> str: + super_repr_html = getattr(super(), "_repr_html_", None) + if super_repr_html is None: + return "" + if super_repr_html() == self.__repr__(): + return "" + return super_repr_html() + def keys(self) -> KeysView[_KT]: return self.__mapping.keys() From 9391c0f82db0b06fbe2406ffdd31ca7207c2bf2d Mon Sep 17 00:00:00 2001 From: dk Date: Fri, 16 Aug 2024 15:19:55 +0700 Subject: [PATCH 2/4] [syft/dicttuple] return `[]` as repr for empty DictTuple --- packages/syft/src/syft/types/dicttuple.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/types/dicttuple.py b/packages/syft/src/syft/types/dicttuple.py index 7b357fdb2e3..7b97d6c5a85 100644 --- a/packages/syft/src/syft/types/dicttuple.py +++ b/packages/syft/src/syft/types/dicttuple.py @@ -236,14 +236,15 @@ def __getitem__(self, __key: _KT | slice | SupportsIndex, /) -> _VT | Self: return super().__getitem__(self.__mapping[__key]) def __repr__(self) -> str: - return f"{self.__class__.__qualname__}{super().__repr__()}" + # return f"{self.__class__.__qualname__}{super().__repr__()}" + return "[]" def _repr_html_(self) -> str: super_repr_html = getattr(super(), "_repr_html_", None) if super_repr_html is None: - return "" - if super_repr_html() == self.__repr__(): - return "" + return super().__repr__() + if super_repr_html() == self.__repr__(): # empty DictTuple + return "[]" return super_repr_html() def keys(self) -> KeysView[_KT]: From 679b923d42341e9bc377be0933e8412d6eaf2e9c Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 19 Aug 2024 15:22:58 +0700 Subject: [PATCH 3/4] [syft/dicttuple] shows "0 records" instead of "[]" if dicttuple is empty Co-authored-by: Kien Dang --- packages/syft/src/syft/types/dicttuple.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/types/dicttuple.py b/packages/syft/src/syft/types/dicttuple.py index 7b97d6c5a85..2e6516259a1 100644 --- a/packages/syft/src/syft/types/dicttuple.py +++ b/packages/syft/src/syft/types/dicttuple.py @@ -236,15 +236,14 @@ def __getitem__(self, __key: _KT | slice | SupportsIndex, /) -> _VT | Self: return super().__getitem__(self.__mapping[__key]) def __repr__(self) -> str: - # return f"{self.__class__.__qualname__}{super().__repr__()}" - return "[]" + return f"{self.__class__.__qualname__}{super().__repr__()}" def _repr_html_(self) -> str: super_repr_html = getattr(super(), "_repr_html_", None) if super_repr_html is None: return super().__repr__() - if super_repr_html() == self.__repr__(): # empty DictTuple - return "[]" + if len(self) == 0: # empty DictTuple + return "0 records" return super_repr_html() def keys(self) -> KeysView[_KT]: From 1e7cb257b4d882c73b14cb6566102fe5adda5d97 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Tue, 20 Aug 2024 10:21:00 +0700 Subject: [PATCH 4/4] small fix to dicttuple repr Co-authored-by: Kien Dang --- packages/syft/src/syft/types/dicttuple.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/types/dicttuple.py b/packages/syft/src/syft/types/dicttuple.py index 2e6516259a1..f82c23528fe 100644 --- a/packages/syft/src/syft/types/dicttuple.py +++ b/packages/syft/src/syft/types/dicttuple.py @@ -241,7 +241,7 @@ def __repr__(self) -> str: def _repr_html_(self) -> str: super_repr_html = getattr(super(), "_repr_html_", None) if super_repr_html is None: - return super().__repr__() + return repr(self) if len(self) == 0: # empty DictTuple return "0 records" return super_repr_html()