mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-10 03:37:51 +02:00
style(langgraph): format lint
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user