diff --git a/libs/checkpoint-postgres/pyproject.toml b/libs/checkpoint-postgres/pyproject.toml index 180166b86..864ba2c00 100644 --- a/libs/checkpoint-postgres/pyproject.toml +++ b/libs/checkpoint-postgres/pyproject.toml @@ -64,6 +64,7 @@ lint.select = [ "UP", # pyupgrade "B", # flake8-bugbear "I", # isort + "PLC0415", # import-outside-top-level "UP", # pyupgrade ] lint.ignore = ["E501", "B008"] diff --git a/libs/checkpoint-postgres/tests/test_async.py b/libs/checkpoint-postgres/tests/test_async.py index fd42146cf..ec941da90 100644 --- a/libs/checkpoint-postgres/tests/test_async.py +++ b/libs/checkpoint-postgres/tests/test_async.py @@ -380,13 +380,15 @@ async def test_delta_channel_chain_reconstruction(saver_name: str) -> None: "langgraph.channels.delta", reason="langgraph core not installed" ) - from typing import Annotated + # Deferred on purpose: langgraph core is not a test dependency of this + # package, so these must stay behind the importorskip above. + from typing import Annotated # noqa: PLC0415 - from langchain_core.messages import AIMessage, HumanMessage - from langgraph.channels.delta import DeltaChannel - from langgraph.graph import START, StateGraph - from langgraph.graph.message import _messages_delta_reducer - from typing_extensions import TypedDict + from langchain_core.messages import AIMessage, HumanMessage # noqa: PLC0415 + from langgraph.channels.delta import DeltaChannel # noqa: PLC0415 + from langgraph.graph import START, StateGraph # noqa: PLC0415 + from langgraph.graph.message import _messages_delta_reducer # noqa: PLC0415 + from typing_extensions import TypedDict # noqa: PLC0415 class State(TypedDict): messages: Annotated[list, DeltaChannel(_messages_delta_reducer)] diff --git a/libs/checkpoint-sqlite/pyproject.toml b/libs/checkpoint-sqlite/pyproject.toml index c0a040655..a9d6c945f 100644 --- a/libs/checkpoint-sqlite/pyproject.toml +++ b/libs/checkpoint-sqlite/pyproject.toml @@ -62,6 +62,7 @@ lint.select = [ "UP", # pyupgrade "B", # flake8-bugbear "I", # isort + "PLC0415", # import-outside-top-level "UP", # pyupgrade ] lint.ignore = ["E501", "B008"] diff --git a/libs/checkpoint-sqlite/tests/test_conformance_delta.py b/libs/checkpoint-sqlite/tests/test_conformance_delta.py index ba0e90f18..d900855d1 100644 --- a/libs/checkpoint-sqlite/tests/test_conformance_delta.py +++ b/libs/checkpoint-sqlite/tests/test_conformance_delta.py @@ -10,14 +10,14 @@ pytest.importorskip( ) pytest.importorskip("aiosqlite", reason="aiosqlite not installed") +from langgraph.checkpoint.conformance import validate # noqa: E402 +from langgraph.checkpoint.conformance.initializer import checkpointer_test # noqa: E402 + +from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver # noqa: E402 + @pytest.mark.asyncio async def test_delta_channel_conformance(): - from langgraph.checkpoint.conformance import validate - from langgraph.checkpoint.conformance.initializer import checkpointer_test - - from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver - @checkpointer_test(name="AsyncSqliteSaver") async def sqlite_saver(): async with AsyncSqliteSaver.from_conn_string(":memory:") as saver: diff --git a/libs/checkpoint-sqlite/tests/test_store.py b/libs/checkpoint-sqlite/tests/test_store.py index e930208f1..d4b06847e 100644 --- a/libs/checkpoint-sqlite/tests/test_store.py +++ b/libs/checkpoint-sqlite/tests/test_store.py @@ -1,7 +1,11 @@ +import math import os +import random import re import tempfile +import time import uuid +from collections import Counter, defaultdict from collections.abc import Generator, Iterable from contextlib import contextmanager from typing import Any, Literal, cast @@ -33,10 +37,6 @@ class CharacterEmbeddings(Embeddings): def __init__(self, dims: int = 50, seed: int = 42): """Initialize with embedding dimensions and random seed.""" - import math - import random - from collections import defaultdict - self._rng = random.Random(seed) self.dims = dims # Create projection vector for each character lazily @@ -48,9 +48,6 @@ class CharacterEmbeddings(Embeddings): def _embed_one(self, text: str) -> list[float]: """Embed a single text.""" - import math - from collections import Counter - counts = Counter(text) total = sum(counts.values()) @@ -338,8 +335,6 @@ class TestSqliteStore: # Test update # Small delay to ensure the updated timestamp is different - import time - time.sleep(0.01) updated_value = {"title": "Updated Document", "content": "Hello, Updated!"}