From cc9a97a47723e796dd5725670214f339461f6588 Mon Sep 17 00:00:00 2001 From: Sadiq Khan Date: Mon, 15 Sep 2025 19:15:34 +0530 Subject: [PATCH] docs(core): add type hints to BaseStore example code (#32946) ## Summary - Add comprehensive type hints to the MyInMemoryStore example code in BaseStore docstring - Improve documentation quality and educational value for developers - Align with LangChain's coding standards requiring type hints on all Python code ## Changes Made - Added return type annotations to all methods (__init__, mget, mset, mdelete, yield_keys) - Added parameter type annotations using proper generic types (Sequence, Iterator) - Added instance variable type annotation for the store attribute - Used modern Python union syntax (str | None) for optional types ## Test Plan - Verified Python syntax validity with ast.parse() - No functional changes to actual code, only documentation improvements - Example code now follows best practices and coding standards This change improves the educational value of the example code and ensures consistency with LangChain's requirement that "All Python code MUST include type hints and return types" as specified in the development guidelines. --------- Co-authored-by: sadiqkhzn Co-authored-by: Mason Daugherty --- libs/core/langchain_core/stores.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/core/langchain_core/stores.py b/libs/core/langchain_core/stores.py index 7f51b4c4b5a..939be003748 100644 --- a/libs/core/langchain_core/stores.py +++ b/libs/core/langchain_core/stores.py @@ -56,22 +56,22 @@ class BaseStore(ABC, Generic[K, V]): class MyInMemoryStore(BaseStore[str, int]): - def __init__(self): - self.store = {} + def __init__(self) -> None: + self.store: dict[str, int] = {} - def mget(self, keys): + def mget(self, keys: Sequence[str]) -> list[Optional[int]]: return [self.store.get(key) for key in keys] - def mset(self, key_value_pairs): + def mset(self, key_value_pairs: Sequence[tuple[str, int]]) -> None: for key, value in key_value_pairs: self.store[key] = value - def mdelete(self, keys): + def mdelete(self, keys: Sequence[str]) -> None: for key in keys: if key in self.store: del self.store[key] - def yield_keys(self, prefix=None): + def yield_keys(self, prefix: Optional[str] = None) -> Iterator[str]: if prefix is None: yield from self.store.keys() else: