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 <sadiqkhzn@users.noreply.github.com>
Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
Sadiq Khan
2025-09-15 19:15:34 +05:30
committed by GitHub
parent ee17adb022
commit cc9a97a477

View File

@@ -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: