Skip to content

Commit 407e18d

Browse files
[python/knowpro] storage.py: Add ListStorage class; and two small tweaks (#1441)
The `ListStorage` storage provider just returns plain lists for messages and semantic refs, showing that in practice these are adequate. Also: - Remove` get_all()` from class `Collection `-- just use` c[:]`. It was unused. - Replace `collection._get_slice(start_at, start_at + batch_size)` with `collection[start_at : start_at + batch_size]`.
1 parent 27c85d6 commit 407e18d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

python/ta/typeagent/knowpro/storage.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def _get_multiple(self, ordinals: list[TOrdinal]) -> list[T]:
5555
"""Retrieve multiple items by their ordinals."""
5656
return [self._get(ordinal) for ordinal in ordinals]
5757

58-
def get_all(self) -> list[T]:
59-
"""Retrieve all items in the collection."""
60-
return self.items
61-
6258
@property
6359
def is_persistent(self) -> bool:
6460
return False
@@ -101,6 +97,27 @@ def close(self) -> None:
10197
pass
10298

10399

100+
class ListStorageProvider(IStorageProvider):
101+
"""A storage provider that uses a list to store items."""
102+
103+
def create_message_collection[TMessage: IMessage](
104+
self,
105+
serializer: JsonSerializer[TMessage] | type[TMessage] | None = None,
106+
) -> MessageCollection[TMessage]:
107+
"""Create a new message collection."""
108+
if isinstance(serializer, JsonSerializer):
109+
raise ValueError("MemoryStorageProvider does not use a serializer.")
110+
return [] # type: ignore[return-value]
111+
112+
def create_semantic_ref_collection(self) -> SemanticRefCollection:
113+
"""Create a new semantic reference collection."""
114+
return [] # type: ignore[return-value]
115+
116+
def close(self) -> None:
117+
"""Close the storage provider."""
118+
pass
119+
120+
104121
# TODO: The rest of this file is not currently used.
105122

106123

@@ -120,7 +137,7 @@ def get_batches_from_collection[T](
120137
"""Generate batches of items from a collection."""
121138
start_at = start_at_ordinal
122139
while True:
123-
batch = collection._get_slice(start_at, start_at + batch_size)
140+
batch = collection[start_at : start_at + batch_size]
124141
if not batch:
125142
break
126143
yield Batch(start_at=start_at, value=batch)

0 commit comments

Comments
 (0)