Skip to content

Commit 51a098d

Browse files
mgr/smb: document ResourceEntry base class methods better
Add docstrings to many previously undocumented methods. Add a real exception instead of an assert when getting a real resource object. Signed-off-by: John Mulligan <[email protected]>
1 parent c81a666 commit 51a098d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/pybind/mgr/smb/internal.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,31 @@ def __init__(self, key: str, config_entry: ConfigEntry) -> None:
5353

5454
@property
5555
def uri(self) -> str:
56+
"""Return a unique URI for this store entry."""
5657
return self.config_entry.uri
5758

5859
def get(self) -> SMBResource:
60+
"""Fetch a single smb resource object from the underlying store."""
5961
return one(resources.load(self.config_entry.get()))
6062

6163
def get_resource_type(self, cls: Type[T]) -> T:
64+
"""Fetch an smb resource matching the supplied type from the
65+
underlying store.
66+
"""
6267
obj = self.get()
63-
assert isinstance(obj, cls), f"{obj!r} is not a {cls}"
68+
if not isinstance(obj, cls):
69+
raise TypeError(f"{obj!r} is not a {cls}")
6470
return obj
6571

6672
def set(self, resource: Simplifiable) -> None:
73+
"""Given a serializable resource object, save it to the store."""
6774
self.config_entry.set(resource.to_simplified())
6875

6976
def create_or_update(self, resource: Simplifiable) -> State:
77+
"""Given a serializable resource object, save it to the store,
78+
returning a state value indicating if the object was created
79+
or updated.
80+
"""
7081
try:
7182
previous = self.config_entry.get()
7283
except KeyError:
@@ -78,23 +89,33 @@ def create_or_update(self, resource: Simplifiable) -> State:
7889
return State.CREATED if previous is None else State.UPDATED
7990

8091
def remove(self) -> bool:
92+
"""Remove an object from the underlying store."""
8193
return self.config_entry.remove()
8294

8395
@classmethod
8496
def ids(
8597
cls, store: ConfigStoreListing
8698
) -> Union[Collection[str], Collection[Tuple[str, str]]]:
99+
"""Return a collection of id values representing all entries
100+
in a particular namespace within the store.
101+
"""
87102
raise NotImplementedError()
88103

89104
@classmethod
90105
def from_store_by_key(
91106
cls, store: ConfigStore, key: Union[str, ResourceKey]
92107
) -> Self:
108+
"""Return a new resource entry object bound to the given store
109+
and identified by the given key.
110+
"""
93111
_key = str(key)
94112
return cls(_key, store[str(cls.namespace), _key])
95113

96114
@classmethod
97115
def to_key(cls, resource: SMBResource) -> ResourceKey:
116+
"""Return a key object uniquely identifiying a resource within a
117+
particular namespace.
118+
"""
98119
raise NotImplementedError()
99120

100121

0 commit comments

Comments
 (0)