Skip to content

The agent engineering platform.

fix(core): make `yield_keys` prefix keyword-only to match `BaseStore` (#34659)

Krud-xd22cfaf7c624
diff --git a/libs/core/langchain_core/stores.py b/libs/core/langchain_core/stores.py
index 77408d6096..e133b9a226 100644
--- a/libs/core/langchain_core/stores.py
+++ b/libs/core/langchain_core/stores.py
@@ -205,7 +205,7 @@ class InMemoryBaseStore(BaseStore[str, V], Generic[V]):
async def amdelete(self, keys: Sequence[str]) -> None:
self.mdelete(keys)
- def yield_keys(self, prefix: str | None = None) -> Iterator[str]:
+ def yield_keys(self, *, prefix: str | None = None) -> Iterator[str]:
"""Get an iterator over keys that match the given prefix.
Args:
@@ -221,7 +221,7 @@ class InMemoryBaseStore(BaseStore[str, V], Generic[V]):
if key.startswith(prefix):
yield key
- async def ayield_keys(self, prefix: str | None = None) -> AsyncIterator[str]:
+ async def ayield_keys(self, *, prefix: str | None = None) -> AsyncIterator[str]:
"""Async get an async iterator over keys that match the given prefix.
Args:
diff --git a/libs/langchain/langchain_classic/storage/file_system.py b/libs/langchain/langchain_classic/storage/file_system.py
index 67a0a76f5a..047162e7be 100644
--- a/libs/langchain/langchain_classic/storage/file_system.py
+++ b/libs/langchain/langchain_classic/storage/file_system.py
@@ -148,7 +148,7 @@ class LocalFileStore(ByteStore):
if full_path.exists():
full_path.unlink()
- def yield_keys(self, prefix: str | None = None) -> Iterator[str]:
+ def yield_keys(self, *, prefix: str | None = None) -> Iterator[str]:
"""Get an iterator over keys that match the given prefix.
Args:
diff --git a/libs/langchain/tests/unit_tests/storage/test_filesystem.py b/libs/langchain/tests/unit_tests/storage/test_filesystem.py
index 63e91c9070..3406f4c83a 100644
--- a/libs/langchain/tests/unit_tests/storage/test_filesystem.py
+++ b/libs/langchain/tests/unit_tests/storage/test_filesystem.py
@@ -140,13 +140,13 @@ def test_catches_forbidden_keys(file_store: LocalFileStore) -> None:
with pytest.raises(InvalidKeyException):
file_store.mset([("/etc", b"value1")])
with pytest.raises(InvalidKeyException):
- list(file_store.yield_keys("/etc/passwd"))
+ list(file_store.yield_keys(prefix="/etc/passwd"))
with pytest.raises(InvalidKeyException):
file_store.mget(["/etc/passwd"])
# check relative paths
with pytest.raises(InvalidKeyException):
- list(file_store.yield_keys(".."))
+ list(file_store.yield_keys(prefix=".."))
with pytest.raises(InvalidKeyException):
file_store.mget(["../etc/passwd"])
@@ -155,4 +155,4 @@ def test_catches_forbidden_keys(file_store: LocalFileStore) -> None:
file_store.mset([("../etc", b"value1")])
with pytest.raises(InvalidKeyException):
- list(file_store.yield_keys("../etc/passwd"))
+ list(file_store.yield_keys(prefix="../etc/passwd"))