Skip to content

Commit

Permalink
Merge pull request #9163 from khoaguin/fix-repr-no-datasets
Browse files Browse the repository at this point in the history
Fix `dataset.getall()` shows `DictTuple()` when there are no datasets
  • Loading branch information
madhavajay authored Aug 30, 2024
2 parents b3e74af + e7ef370 commit 943c588
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/syft/src/syft/service/worker/worker_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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"""
<div class='syft-dataset'>
<h3>{self.name}</h3>
Expand Down
8 changes: 8 additions & 0 deletions packages/syft/src/syft/types/dicttuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 repr(self)
if len(self) == 0: # empty DictTuple
return "0 records"
return super_repr_html()

def keys(self) -> KeysView[_KT]:
return self.__mapping.keys()

Expand Down

0 comments on commit 943c588

Please sign in to comment.