From 881b07cf7f20ba34dc37a3cab4c8fdfdd86012ca Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 31 Mar 2025 16:36:16 -0700 Subject: [PATCH] Lint --- libs/langgraph/langgraph/channels/any_value.py | 4 ++-- libs/langgraph/langgraph/channels/base.py | 6 +++--- libs/langgraph/langgraph/channels/binop.py | 10 ++-------- .../langgraph/channels/dynamic_barrier_value.py | 3 +-- libs/langgraph/langgraph/channels/ephemeral_value.py | 4 ++-- libs/langgraph/langgraph/channels/last_value.py | 4 ++-- .../langgraph/channels/named_barrier_value.py | 4 ++-- libs/langgraph/langgraph/channels/topic.py | 11 +++++------ libs/langgraph/langgraph/channels/untracked_value.py | 4 ++-- libs/langgraph/langgraph/utils/future.py | 2 +- 10 files changed, 22 insertions(+), 30 deletions(-) diff --git a/libs/langgraph/langgraph/channels/any_value.py b/libs/langgraph/langgraph/channels/any_value.py index 412436d4f..0276030aa 100644 --- a/libs/langgraph/langgraph/channels/any_value.py +++ b/libs/langgraph/langgraph/channels/any_value.py @@ -1,4 +1,4 @@ -from typing import Any, Generic, Optional, Sequence, Type +from typing import Any, Generic, Sequence, Type from typing_extensions import Self @@ -30,7 +30,7 @@ class AnyValue(Generic[Value], BaseChannel[Value, Value, Value]): """The type of the update received by the channel.""" return self.typ - def from_checkpoint(self, checkpoint: Optional[Value]) -> Self: + def from_checkpoint(self, checkpoint: Value) -> Self: empty = self.__class__(self.typ) empty.key = self.key if checkpoint is not MISSING: diff --git a/libs/langgraph/langgraph/channels/base.py b/libs/langgraph/langgraph/channels/base.py index b9239be7a..82fd059d1 100644 --- a/libs/langgraph/langgraph/channels/base.py +++ b/libs/langgraph/langgraph/channels/base.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any, Generic, Optional, Sequence, TypeVar +from typing import Any, Generic, Sequence, TypeVar from typing_extensions import Self @@ -29,14 +29,14 @@ class BaseChannel(Generic[Value, Update, C], ABC): # serialize/deserialize methods - def checkpoint(self) -> Optional[C]: + def checkpoint(self) -> C: """Return a serializable representation of the channel's current state. Raises EmptyChannelError if the channel is empty (never updated yet), or doesn't support checkpoints.""" return self.get() @abstractmethod - def from_checkpoint(self, checkpoint: Optional[C]) -> Self: + def from_checkpoint(self, checkpoint: C) -> Self: """Return a new identical channel, optionally initialized from a checkpoint. If the checkpoint contains complex data structures, they should be copied.""" diff --git a/libs/langgraph/langgraph/channels/binop.py b/libs/langgraph/langgraph/channels/binop.py index 9ed2f0ca5..eb90cae8c 100644 --- a/libs/langgraph/langgraph/channels/binop.py +++ b/libs/langgraph/langgraph/channels/binop.py @@ -1,11 +1,5 @@ import collections.abc -from typing import ( - Callable, - Generic, - Optional, - Sequence, - Type, -) +from typing import Callable, Generic, Sequence, Type from typing_extensions import NotRequired, Required, Self @@ -72,7 +66,7 @@ class BinaryOperatorAggregate(Generic[Value], BaseChannel[Value, Value, Value]): """The type of the update received by the channel.""" return self.typ - def from_checkpoint(self, checkpoint: Optional[Value]) -> Self: + def from_checkpoint(self, checkpoint: Value) -> Self: empty = self.__class__(self.typ, self.operator) empty.key = self.key if checkpoint is not MISSING: diff --git a/libs/langgraph/langgraph/channels/dynamic_barrier_value.py b/libs/langgraph/langgraph/channels/dynamic_barrier_value.py index d9ea1ba8b..511c311f3 100644 --- a/libs/langgraph/langgraph/channels/dynamic_barrier_value.py +++ b/libs/langgraph/langgraph/channels/dynamic_barrier_value.py @@ -50,8 +50,7 @@ class DynamicBarrierValue( return (self.names, self.seen) def from_checkpoint( - self, - checkpoint: Optional[tuple[Optional[set[Value]], set[Value]]], + self, checkpoint: tuple[Optional[set[Value]], set[Value]] ) -> Self: empty = self.__class__(self.typ) empty.key = self.key diff --git a/libs/langgraph/langgraph/channels/ephemeral_value.py b/libs/langgraph/langgraph/channels/ephemeral_value.py index 23e80c017..242149fe6 100644 --- a/libs/langgraph/langgraph/channels/ephemeral_value.py +++ b/libs/langgraph/langgraph/channels/ephemeral_value.py @@ -1,4 +1,4 @@ -from typing import Any, Generic, Optional, Sequence, Type +from typing import Any, Generic, Sequence, Type from typing_extensions import Self @@ -30,7 +30,7 @@ class EphemeralValue(Generic[Value], BaseChannel[Value, Value, Value]): """The type of the update received by the channel.""" return self.typ - def from_checkpoint(self, checkpoint: Optional[Value]) -> Self: + def from_checkpoint(self, checkpoint: Value) -> Self: empty = self.__class__(self.typ, self.guard) empty.key = self.key if checkpoint is not MISSING: diff --git a/libs/langgraph/langgraph/channels/last_value.py b/libs/langgraph/langgraph/channels/last_value.py index dd67872b8..32a951a4b 100644 --- a/libs/langgraph/langgraph/channels/last_value.py +++ b/libs/langgraph/langgraph/channels/last_value.py @@ -1,4 +1,4 @@ -from typing import Any, Generic, Optional, Sequence, Type +from typing import Any, Generic, Sequence, Type from typing_extensions import Self @@ -34,7 +34,7 @@ class LastValue(Generic[Value], BaseChannel[Value, Value, Value]): """The type of the update received by the channel.""" return self.typ - def from_checkpoint(self, checkpoint: Optional[Value]) -> Self: + def from_checkpoint(self, checkpoint: Value) -> Self: empty = self.__class__(self.typ) empty.key = self.key if checkpoint is not MISSING: diff --git a/libs/langgraph/langgraph/channels/named_barrier_value.py b/libs/langgraph/langgraph/channels/named_barrier_value.py index 4402dce95..2145d0f73 100644 --- a/libs/langgraph/langgraph/channels/named_barrier_value.py +++ b/libs/langgraph/langgraph/channels/named_barrier_value.py @@ -1,4 +1,4 @@ -from typing import Generic, Optional, Sequence, Type +from typing import Generic, Sequence, Type from typing_extensions import Self @@ -36,7 +36,7 @@ class NamedBarrierValue(Generic[Value], BaseChannel[Value, Value, set[Value]]): def checkpoint(self) -> set[Value]: return self.seen - def from_checkpoint(self, checkpoint: Optional[set[Value]]) -> Self: + def from_checkpoint(self, checkpoint: set[Value]) -> Self: empty = self.__class__(self.typ, self.names) empty.key = self.key if checkpoint is not MISSING: diff --git a/libs/langgraph/langgraph/channels/topic.py b/libs/langgraph/langgraph/channels/topic.py index 2f3e73955..8fc998353 100644 --- a/libs/langgraph/langgraph/channels/topic.py +++ b/libs/langgraph/langgraph/channels/topic.py @@ -1,4 +1,4 @@ -from typing import Any, Generic, Iterator, Optional, Sequence, Type, Union +from typing import Any, Generic, Iterator, Sequence, Type, Union from typing_extensions import Self @@ -17,9 +17,7 @@ def flatten(values: Sequence[Union[Value, list[Value]]]) -> Iterator[Value]: class Topic( Generic[Value], - BaseChannel[ - Sequence[Value], Union[Value, list[Value]], tuple[set[Value], list[Value]] - ], + BaseChannel[Sequence[Value], Union[Value, list[Value]], list[Value]], ): """A configurable PubSub Topic. @@ -50,14 +48,15 @@ class Topic( """The type of the update received by the channel.""" return Union[self.typ, list[self.typ]] # type: ignore[name-defined] - def checkpoint(self) -> tuple[set[Value], list[Value]]: + def checkpoint(self) -> list[Value]: return self.values - def from_checkpoint(self, checkpoint: Optional[list[Value]]) -> Self: + def from_checkpoint(self, checkpoint: list[Value]) -> Self: empty = self.__class__(self.typ, self.accumulate) empty.key = self.key if checkpoint is not MISSING: if isinstance(checkpoint, tuple): + # backwards compatibility empty.values = checkpoint[1] else: empty.values = checkpoint diff --git a/libs/langgraph/langgraph/channels/untracked_value.py b/libs/langgraph/langgraph/channels/untracked_value.py index f9168131e..cc9c99bee 100644 --- a/libs/langgraph/langgraph/channels/untracked_value.py +++ b/libs/langgraph/langgraph/channels/untracked_value.py @@ -1,4 +1,4 @@ -from typing import Generic, Optional, Sequence, Type +from typing import Generic, Sequence, Type from typing_extensions import Self @@ -33,7 +33,7 @@ class UntrackedValue(Generic[Value], BaseChannel[Value, Value, Value]): def checkpoint(self) -> Value: raise EmptyChannelError() - def from_checkpoint(self, checkpoint: Optional[Value]) -> Self: + def from_checkpoint(self, checkpoint: Value) -> Self: empty = self.__class__(self.typ, self.guard) empty.key = self.key return empty diff --git a/libs/langgraph/langgraph/utils/future.py b/libs/langgraph/langgraph/utils/future.py index a311133df..a373d1cce 100644 --- a/libs/langgraph/langgraph/utils/future.py +++ b/libs/langgraph/langgraph/utils/future.py @@ -164,7 +164,7 @@ def _ensure_future( elif EAGER_NOT_SUPPORTED or lazy: return loop.create_task(coro_or_future, name=name, context=context) else: - return asyncio.eager_task_factory( + return asyncio.eager_task_factory( # type:ignore[attr-defined] loop, coro_or_future, name=name, context=context ) except RuntimeError: