mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
style(core): add ruff rules TC (#34476)
* Fixed a few TC * Added a few Pydantic classes to `flake8-type-checking.runtime-evaluated-base-classes` (not as much as I would have imagined) * Added a few `noqa: TC` * Activated TC rules
This commit is contained in:
committed by
GitHub
parent
451e8496e7
commit
1f403cf612
@@ -12,7 +12,6 @@ from concurrent.futures import ThreadPoolExecutor
|
|||||||
from contextlib import asynccontextmanager, contextmanager
|
from contextlib import asynccontextmanager, contextmanager
|
||||||
from contextvars import copy_context
|
from contextvars import copy_context
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar, cast
|
from typing import TYPE_CHECKING, Any, TypeVar, cast
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from langsmith.run_helpers import get_tracing_context
|
from langsmith.run_helpers import get_tracing_context
|
||||||
from typing_extensions import Self, override
|
from typing_extensions import Self, override
|
||||||
@@ -44,6 +43,7 @@ from langchain_core.utils.uuid import uuid7
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import AsyncGenerator, Coroutine, Generator, Sequence
|
from collections.abc import AsyncGenerator, Coroutine, Generator, Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from tenacity import RetryCallState
|
from tenacity import RetryCallState
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ from typing import (
|
|||||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||||
from typing_extensions import TypedDict, override
|
from typing_extensions import TypedDict, override
|
||||||
|
|
||||||
from langchain_core.caches import BaseCache
|
from langchain_core.caches import BaseCache # noqa: TC001
|
||||||
from langchain_core.callbacks import Callbacks
|
from langchain_core.callbacks import Callbacks # noqa: TC001
|
||||||
from langchain_core.globals import get_verbose
|
from langchain_core.globals import get_verbose
|
||||||
from langchain_core.messages import (
|
from langchain_core.messages import (
|
||||||
AIMessage,
|
AIMessage,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import contextlib
|
|||||||
import json
|
import json
|
||||||
import typing
|
import typing
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping # noqa: TC003
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
@@ -22,7 +22,7 @@ from typing_extensions import Self, override
|
|||||||
|
|
||||||
from langchain_core.exceptions import ErrorCode, create_message
|
from langchain_core.exceptions import ErrorCode, create_message
|
||||||
from langchain_core.load import dumpd
|
from langchain_core.load import dumpd
|
||||||
from langchain_core.output_parsers.base import BaseOutputParser
|
from langchain_core.output_parsers.base import BaseOutputParser # noqa: TC001
|
||||||
from langchain_core.prompt_values import (
|
from langchain_core.prompt_values import (
|
||||||
ChatPromptValueConcrete,
|
ChatPromptValueConcrete,
|
||||||
PromptValue,
|
PromptValue,
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import uuid
|
|
||||||
|
# Cannot move uuid to TYPE_CHECKING as RunnableConfig is used in Pydantic models
|
||||||
|
import uuid # noqa: TC003
|
||||||
import warnings
|
import warnings
|
||||||
from collections.abc import Awaitable, Callable, Generator, Iterable, Iterator, Sequence
|
from collections.abc import Awaitable, Callable, Generator, Iterable, Iterator, Sequence
|
||||||
from concurrent.futures import Executor, Future, ThreadPoolExecutor
|
from concurrent.futures import Executor, Future, ThreadPoolExecutor
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable, Mapping
|
from collections.abc import Mapping
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
@@ -31,7 +31,7 @@ from langchain_core.runnables.utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import AsyncIterator, Iterator
|
from collections.abc import AsyncIterator, Callable, Iterator
|
||||||
|
|
||||||
|
|
||||||
class RouterInput(TypedDict):
|
class RouterInput(TypedDict):
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import asyncio
|
|||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections.abc import Mapping, Sequence
|
|
||||||
|
# Cannot move to TYPE_CHECKING as Mapping and Sequence are needed at runtime by
|
||||||
|
# RunnableConfigurableFields.
|
||||||
|
from collections.abc import Mapping, Sequence # noqa: TC003
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import json
|
|||||||
import typing
|
import typing
|
||||||
import warnings
|
import warnings
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable # noqa: TC003
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ from typing import TYPE_CHECKING, Literal
|
|||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from langchain_core.callbacks import Callbacks
|
# Cannot move Callbacks and Document to TYPE_CHECKING as StructuredTool's
|
||||||
from langchain_core.documents import Document
|
# func/coroutine parameter annotations are evaluated at runtime.
|
||||||
|
from langchain_core.callbacks import Callbacks # noqa: TC001
|
||||||
|
from langchain_core.documents import Document # noqa: TC001
|
||||||
from langchain_core.prompts import (
|
from langchain_core.prompts import (
|
||||||
BasePromptTemplate,
|
BasePromptTemplate,
|
||||||
PromptTemplate,
|
PromptTemplate,
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ from typing import (
|
|||||||
|
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
|
# Cannot move to TYPE_CHECKING as _run/_arun parameter annotations are needed at runtime
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
AsyncCallbackManagerForToolRun,
|
AsyncCallbackManagerForToolRun, # noqa: TC001
|
||||||
CallbackManagerForToolRun,
|
CallbackManagerForToolRun, # noqa: TC001
|
||||||
)
|
)
|
||||||
from langchain_core.runnables import RunnableConfig, run_in_executor
|
from langchain_core.runnables import RunnableConfig, run_in_executor
|
||||||
from langchain_core.tools.base import (
|
from langchain_core.tools.base import (
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ from typing import (
|
|||||||
from pydantic import Field, SkipValidation
|
from pydantic import Field, SkipValidation
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
|
# Cannot move to TYPE_CHECKING as _run/_arun parameter annotations are needed at runtime
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
AsyncCallbackManagerForToolRun,
|
AsyncCallbackManagerForToolRun, # noqa: TC001
|
||||||
CallbackManagerForToolRun,
|
CallbackManagerForToolRun, # noqa: TC001
|
||||||
)
|
)
|
||||||
from langchain_core.runnables import RunnableConfig, run_in_executor
|
from langchain_core.runnables import RunnableConfig, run_in_executor
|
||||||
from langchain_core.tools.base import (
|
from langchain_core.tools.base import (
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from typing import (
|
|||||||
TypeVar,
|
TypeVar,
|
||||||
cast,
|
cast,
|
||||||
)
|
)
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
from typing_extensions import NotRequired, override
|
from typing_extensions import NotRequired, override
|
||||||
|
|
||||||
@@ -47,6 +46,7 @@ from langchain_core.utils.uuid import uuid7
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import AsyncIterator, Iterator, Sequence
|
from collections.abc import AsyncIterator, Iterator, Sequence
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.runnables import Runnable, RunnableConfig
|
from langchain_core.runnables import Runnable, RunnableConfig
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import logging
|
|||||||
import types
|
import types
|
||||||
import typing
|
import typing
|
||||||
import uuid
|
import uuid
|
||||||
from collections.abc import Mapping
|
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Annotated,
|
Annotated,
|
||||||
@@ -35,7 +34,7 @@ from langchain_core.utils.json_schema import dereference_refs
|
|||||||
from langchain_core.utils.pydantic import is_basemodel_subclass
|
from langchain_core.utils.pydantic import is_basemodel_subclass
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable, Mapping
|
||||||
|
|
||||||
from langchain_core.tools import BaseTool
|
from langchain_core.tools import BaseTool
|
||||||
|
|
||||||
|
|||||||
@@ -93,9 +93,6 @@ ignore = [
|
|||||||
"PERF203", # Rarely useful
|
"PERF203", # Rarely useful
|
||||||
"PLR09", # Too many something (arg, statements, etc)
|
"PLR09", # Too many something (arg, statements, etc)
|
||||||
"RUF012", # Doesn't play well with Pydantic
|
"RUF012", # Doesn't play well with Pydantic
|
||||||
"TC001", # Doesn't play well with Pydantic
|
|
||||||
"TC002", # Doesn't play well with Pydantic
|
|
||||||
"TC003", # Doesn't play well with Pydantic
|
|
||||||
"TD002", # Missing author in TODO
|
"TD002", # Missing author in TODO
|
||||||
"TD003", # Missing issue link in TODO
|
"TD003", # Missing issue link in TODO
|
||||||
|
|
||||||
@@ -112,7 +109,7 @@ unfixable = [
|
|||||||
flake8-annotations.allow-star-arg-any = true
|
flake8-annotations.allow-star-arg-any = true
|
||||||
flake8-annotations.mypy-init-return = true
|
flake8-annotations.mypy-init-return = true
|
||||||
flake8-builtins.ignorelist = ["id", "input", "type"]
|
flake8-builtins.ignorelist = ["id", "input", "type"]
|
||||||
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
|
flake8-type-checking.runtime-evaluated-base-classes = [ "pydantic.BaseModel", "langchain_core.load.serializable.Serializable", "langchain_core.runnables.base.RunnableSerializable", "langchain_core.language_models.base.BaseLanguageModel", "langchain_core.outputs.generation.Generation", "langchain_core.tools.base.BaseTool",]
|
||||||
pep8-naming.classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
|
pep8-naming.classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
|
||||||
|
|
||||||
[tool.ruff.lint.pydocstyle]
|
[tool.ruff.lint.pydocstyle]
|
||||||
|
|||||||
Reference in New Issue
Block a user