From 7dba4f679131881859128c7af35e6f97d62c7cd3 Mon Sep 17 00:00:00 2001 From: Caspar Broekhuizen Date: Thu, 9 Oct 2025 14:33:30 -0700 Subject: [PATCH] style(langgraph): format lint --- libs/langgraph/langgraph/pregel/_loop.py | 12 +++++++----- libs/langgraph/tests/test_interruption.py | 19 ++++++------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/libs/langgraph/langgraph/pregel/_loop.py b/libs/langgraph/langgraph/pregel/_loop.py index ba737d4ea..e7f9ad88f 100644 --- a/libs/langgraph/langgraph/pregel/_loop.py +++ b/libs/langgraph/langgraph/pregel/_loop.py @@ -316,9 +316,7 @@ class PregelLoop: ] writes_to_save: WritesT = [ w[1:] for w in self.checkpoint_pending_writes if w[0] == task_id - ] + [ - (c, v) for c, v in writes if c != RESUME - ] + ] + [(c, v) for c, v in writes if c != RESUME] self.checkpoint_pending_writes.extend((task_id, c, v) for c, v in writes) else: # build map of existing interrupts for this task for quick lookup @@ -331,7 +329,7 @@ class PregelLoop: for ch, v in writes: if ch == INTERRUPT: # we merge new interrupt writes with existing interrupts writes if they - # occured within the same task (which means they have the same interrupt id) + # occurred within the same task (which means they have the same interrupt id) new_interrupts = v if isinstance(v, list) else list(v) if new_interrupts and ( existing := existing_interrupts_by_id.get(new_interrupts[0].id) @@ -339,7 +337,11 @@ class PregelLoop: # if the graph is invoked with None, we will hit the same interrupt # that was raised before, in this case we don't want to duplicate its write # so we just keep the existing checkpoint writes - v = existing + new_interrupts if self.input is not None else existing + v = ( + existing + new_interrupts + if self.input is not None + else existing + ) writes_to_save.append((ch, v)) else: # we add non-interrupt writes as-is diff --git a/libs/langgraph/tests/test_interruption.py b/libs/langgraph/tests/test_interruption.py index 85de4649b..2a9966264 100644 --- a/libs/langgraph/tests/test_interruption.py +++ b/libs/langgraph/tests/test_interruption.py @@ -583,6 +583,7 @@ async def test_node_with_multiple_interrupts_requires_full_resume_async( assert final_result["input"] == "human_first-human_second-human_third" assert node_counter == 5 + def test_invoke_interrupted_graph_with_none( sync_checkpointer: BaseCheckpointSaver, ) -> None: @@ -617,9 +618,7 @@ def test_invoke_interrupted_graph_with_none( # invoke with None. this should execute the node and the history should # look the same as the first run - partial = graph.invoke( - None, config=config - ) + partial = graph.invoke(None, config=config) second_history = list(graph.get_state_history(config)) remaining_interrupts = partial.get("__interrupt__", []) assert len(remaining_interrupts) == 1 @@ -635,21 +634,17 @@ def test_invoke_interrupted_graph_with_none( assert first_history[0].tasks == second_history[0].tasks # now resume the first interrupt with some value - partial = graph.invoke( - Command(resume="weet"), config=config - ) + partial = graph.invoke(Command(resume="weet"), config=config) print("partial 3", partial) third_history = list(graph.get_state_history(config)) remaining_interrupts = partial.get("__interrupt__", []) assert len(remaining_interrupts) == 1 assert remaining_interrupts[0].value == "second" assert node_counter == 3 - + # invoke with None again. the history should look the same as # the third run - partial = graph.invoke( - None, config=config - ) + partial = graph.invoke(None, config=config) print("partial 4", partial) fourth_history = list(graph.get_state_history(config)) remaining_interrupts = partial.get("__interrupt__", []) @@ -664,9 +659,7 @@ def test_invoke_interrupted_graph_with_none( assert third_history[0].tasks == fourth_history[0].tasks # resume the graph once more with a real value - partial = graph.invoke( - Command(resume="bix"), config=config - ) + partial = graph.invoke(Command(resume="bix"), config=config) remaining_interrupts = partial.get("__interrupt__", []) assert len(remaining_interrupts) == 0 assert node_counter == 5