Raise exception for reducers w wrong signature (#1261)

This commit is contained in:
Nuno Campos
2024-08-07 17:48:07 +00:00
committed by GitHub
parent 9caeeaeeec
commit 6078c408c3
2 changed files with 15 additions and 6 deletions
+6 -6
View File
@@ -725,14 +725,14 @@ def _is_field_binop(typ: Type[Any]) -> Optional[BinaryOperatorAggregate]:
if len(meta) >= 1 and callable(meta[-1]):
sig = signature(meta[0])
params = list(sig.parameters.values())
if len(params) == 2 and len(
[
p
for p in params
if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD)
]
if len(params) == 2 and all(
p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD) for p in params
):
return BinaryOperatorAggregate(typ, meta[0])
else:
raise ValueError(
f"Invalid reducer signature. Expected (a, b) -> c. Got {sig}"
)
return None
+9
View File
@@ -185,6 +185,15 @@ def test_graph_validation() -> None:
with pytest.raises(ValueError, match="Found edge starting at unknown node "):
graph.compile()
def bad_reducer(a):
...
class BadReducerState(TypedDict):
hello: Annotated[str, bad_reducer]
with pytest.raises(ValueError, match="Invalid reducer"):
StateGraph(BadReducerState)
def test_checkpoint_errors() -> None:
class FaultyGetCheckpointer(MemorySaver):