From 5c0c0fb1869a98dc11f1516cfa8e3e25680d2ec0 Mon Sep 17 00:00:00 2001 From: Isaac Francisco <78627776+isahers1@users.noreply.github.com> Date: Thu, 7 Aug 2025 08:46:44 -0700 Subject: [PATCH] fix: mypy issue with conditional edges (#5851) Send should inherit from hashable, and need to use Sequence since List is invariant. https://github.com/langchain-ai/langgraph/issues/5850 --- libs/langgraph/langgraph/graph/_branch.py | 10 +++++----- libs/langgraph/langgraph/graph/state.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libs/langgraph/langgraph/graph/_branch.py b/libs/langgraph/langgraph/graph/_branch.py index 34ff58a61..fc94e1b41 100644 --- a/libs/langgraph/langgraph/graph/_branch.py +++ b/libs/langgraph/langgraph/graph/_branch.py @@ -41,16 +41,16 @@ _Writer = Callable[ def _get_branch_path_input_schema( - path: Callable[..., Hashable | list[Hashable]] - | Callable[..., Awaitable[Hashable | list[Hashable]]] - | Runnable[Any, Hashable | list[Hashable]], + path: Callable[..., Hashable | Sequence[Hashable]] + | Callable[..., Awaitable[Hashable | Sequence[Hashable]]] + | Runnable[Any, Hashable | Sequence[Hashable]], ) -> type[Any] | None: input = None # detect input schema annotation in the branch callable try: callable_: ( - Callable[..., Hashable | list[Hashable]] - | Callable[..., Awaitable[Hashable | list[Hashable]]] + Callable[..., Hashable | Sequence[Hashable]] + | Callable[..., Awaitable[Hashable | Sequence[Hashable]]] | None ) = None if isinstance(path, (RunnableCallable, RunnableLambda)): diff --git a/libs/langgraph/langgraph/graph/state.py b/libs/langgraph/langgraph/graph/state.py index 74c1e496b..2a1a194b7 100644 --- a/libs/langgraph/langgraph/graph/state.py +++ b/libs/langgraph/langgraph/graph/state.py @@ -607,9 +607,9 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): def add_conditional_edges( self, source: str, - path: Callable[..., Hashable | list[Hashable]] - | Callable[..., Awaitable[Hashable | list[Hashable]]] - | Runnable[Any, Hashable | list[Hashable]], + path: Callable[..., Hashable | Sequence[Hashable]] + | Callable[..., Awaitable[Hashable | Sequence[Hashable]]] + | Runnable[Any, Hashable | Sequence[Hashable]], path_map: dict[Hashable, str] | list[str] | None = None, ) -> Self: """Add a conditional edge from the starting node to any number of destination nodes. @@ -710,9 +710,9 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]): def set_conditional_entry_point( self, - path: Callable[..., Hashable | list[Hashable]] - | Callable[..., Awaitable[Hashable | list[Hashable]]] - | Runnable[Any, Hashable | list[Hashable]], + path: Callable[..., Hashable | Sequence[Hashable]] + | Callable[..., Awaitable[Hashable | Sequence[Hashable]]] + | Runnable[Any, Hashable | Sequence[Hashable]], path_map: dict[Hashable, str] | list[str] | None = None, ) -> Self: """Sets a conditional entry point in the graph.