Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storages: add rich repr #494

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/dvc_data/index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ def __init__(
super().__init__(key, read_only=read_only)

def __repr__(self) -> str:
key = self.key
odb = self.odb
index = self.index
read_only = self.read_only
return f"{type(self).__name__}({key=!r}, {odb=!r}, {index=!r}, {read_only=!r})"
params = ", ".join(f"{k}={v!r}" for k, v, *_ in self.__rich_repr__())
return f"{self.__class__.__name__}({params})"

def __rich_repr__(self):
yield "key", self.key
yield "odb", self.odb
yield "index", self.index, None
yield "read_only", self.read_only, False

@property
def fs(self):
Expand Down Expand Up @@ -253,16 +256,15 @@ def __init__(
super().__init__(key, read_only=read_only)

def __repr__(self) -> str:
key = self.key
fs = self.fs
path = self.path
index = self.index
prefix = self.prefix
read_only = self.read_only
return (
f"{self.__class__.__name__}("
f"{key=!r}, {fs=!r}, {path=!r}, {index=!r}, {prefix=!r}, {read_only=!r})"
)
params = ", ".join(f"{k}={v!r}" for k, v, *_ in self.__rich_repr__())
return f"{self.__class__.__name__}({params})"

def __rich_repr__(self):
yield "key", self.key
yield "fs", self.fs
yield "index", self.index, None
yield "prefix", self.prefix, None
yield "read_only", self.read_only, False

@property
def fs(self):
Expand Down Expand Up @@ -340,6 +342,12 @@ class StorageMapping(MutableMapping):
def __init__(self, *args, **kwargs):
self._map = dict(*args, **kwargs)

def __repr__(self):
return f"{self.__class__.__name__}({self._map!r})"

def __rich_repr__(self):
yield self._map

def __setitem__(self, key, value):
self._map[key] = value

Expand Down
Loading