Skip to content

Commit

Permalink
core: Add ruff rules for Pylint PLC (Convention) and PLE (Errors)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Jan 18, 2025
1 parent 1cd4d8d commit 3a291b1
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 51 deletions.
3 changes: 0 additions & 3 deletions libs/core/langchain_core/callbacks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2232,9 +2232,6 @@ async def on_chain_error(
T = TypeVar("T", CallbackManager, AsyncCallbackManager)


H = TypeVar("H", bound=BaseCallbackHandler, covariant=True)


def _configure(
callback_manager_cls: type[T],
inheritable_callbacks: Callbacks = None,
Expand Down
3 changes: 1 addition & 2 deletions libs/core/langchain_core/document_loaders/blob_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from collections.abc import Iterable

# Re-export Blob and PathLike for backwards compatibility
from langchain_core.documents.base import Blob as Blob
from langchain_core.documents.base import PathLike as PathLike
from langchain_core.documents.base import Blob, PathLike


class BlobLoader(ABC):
Expand Down
2 changes: 1 addition & 1 deletion libs/core/langchain_core/messages/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, id: str, **kwargs: Any) -> None:
msg = "RemoveMessage does not support 'content' field."
raise ValueError(msg)

return super().__init__("", id=id, **kwargs)
super().__init__("", id=id, **kwargs)

@classmethod
def get_lc_namespace(cls) -> list[str]:
Expand Down
1 change: 0 additions & 1 deletion libs/core/langchain_core/output_parsers/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from collections import deque
from collections.abc import AsyncIterator, Iterator
from io import StringIO
from typing import Optional as Optional
from typing import TypeVar, Union

from langchain_core.messages import BaseMessage
Expand Down
2 changes: 0 additions & 2 deletions libs/core/langchain_core/output_parsers/string.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional as Optional

from langchain_core.output_parsers.transform import BaseTransformOutputParser


Expand Down
1 change: 0 additions & 1 deletion libs/core/langchain_core/prompts/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any
from typing import Optional as Optional

from pydantic import model_validator

Expand Down
1 change: 0 additions & 1 deletion libs/core/langchain_core/runnables/configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import threading
from abc import abstractmethod
from collections.abc import AsyncIterator, Iterator, Sequence
from collections.abc import Mapping as Mapping
from functools import wraps
from typing import (
Any,
Expand Down
6 changes: 3 additions & 3 deletions libs/core/langchain_core/runnables/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
from langchain_core.runnables.schema import StreamEvent

# Re-export create-model for backwards compatibility
from langchain_core.utils.pydantic import create_model as create_model
from langchain_core.utils.pydantic import create_model # noqa: F401

Input = TypeVar("Input", contravariant=True)
Input = TypeVar("Input", contravariant=True) # noqa: PLC0105
# Output type should implement __concat__, as eg str, list, dict do
Output = TypeVar("Output", covariant=True)
Output = TypeVar("Output", covariant=True) # noqa: PLC0105


async def gated_coro(semaphore: asyncio.Semaphore, coro: Coroutine) -> Any:
Expand Down
71 changes: 39 additions & 32 deletions libs/core/langchain_core/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,49 @@
from __future__ import annotations

from langchain_core.tools.base import (
FILTERED_ARGS as FILTERED_ARGS,
)
from langchain_core.tools.base import (
BaseTool as BaseTool,
)
from langchain_core.tools.base import (
BaseToolkit as BaseToolkit,
)
from langchain_core.tools.base import (
InjectedToolArg as InjectedToolArg,
)
from langchain_core.tools.base import InjectedToolCallId as InjectedToolCallId
from langchain_core.tools.base import SchemaAnnotationError as SchemaAnnotationError
from langchain_core.tools.base import (
ToolException as ToolException,
)
from langchain_core.tools.base import (
_get_runnable_config_param as _get_runnable_config_param,
)
from langchain_core.tools.base import (
create_schema_from_function as create_schema_from_function,
FILTERED_ARGS,
BaseTool,
BaseToolkit,
InjectedToolArg,
InjectedToolCallId,
SchemaAnnotationError,
ToolException,
_get_runnable_config_param,
create_schema_from_function,
)
from langchain_core.tools.convert import (
convert_runnable_to_tool as convert_runnable_to_tool,
convert_runnable_to_tool,
tool,
)
from langchain_core.tools.convert import tool as tool
from langchain_core.tools.render import ToolsRenderer as ToolsRenderer
from langchain_core.tools.render import (
render_text_description as render_text_description,
ToolsRenderer,
render_text_description,
render_text_description_and_args,
)
from langchain_core.tools.render import (
render_text_description_and_args as render_text_description_and_args,
)
from langchain_core.tools.retriever import RetrieverInput as RetrieverInput
from langchain_core.tools.retriever import (
create_retriever_tool as create_retriever_tool,
RetrieverInput,
create_retriever_tool,
)
from langchain_core.tools.simple import Tool as Tool
from langchain_core.tools.structured import StructuredTool as StructuredTool
from langchain_core.tools.simple import Tool
from langchain_core.tools.structured import StructuredTool

__all__ = [
"BaseTool",
"BaseToolkit",
"FILTERED_ARGS",
"SchemaAnnotationError",
"ToolException",
"InjectedToolArg",
"InjectedToolCallId",
"_get_runnable_config_param",
"create_schema_from_function",
"convert_runnable_to_tool",
"tool",
"ToolsRenderer",
"render_text_description",
"render_text_description_and_args",
"RetrieverInput",
"create_retriever_tool",
"Tool",
"StructuredTool",
]
2 changes: 1 addition & 1 deletion libs/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ python = ">=3.12.4"
[tool.poetry.extras]

[tool.ruff.lint]
select = [ "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FLY", "FURB", "I", "ICN", "INT", "LOG", "N", "NPY", "PD", "PIE", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T201", "TID", "UP", "W", "YTT",]
select = [ "ASYNC", "B", "C4", "COM", "DJ", "E", "EM", "EXE", "F", "FLY", "FURB", "I", "ICN", "INT", "LOG", "N", "NPY", "PD", "PIE", "PLC","PLE", "Q", "RSE", "S", "SIM", "SLOT", "T10", "T201", "TID", "UP", "W", "YTT",]
ignore = [ "COM812", "UP007", "W293", "S101", "S110", "S112",]

[tool.coverage.run]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
from typing import Optional as Optional

from langchain_core.caches import InMemoryCache
from langchain_core.language_models import GenericFakeChatModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Module to test base parser implementations."""

from typing import Optional as Optional

from langchain_core.exceptions import OutputParserException
from langchain_core.language_models import GenericFakeChatModel
from langchain_core.messages import AIMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections.abc import AsyncIterator, Sequence
from itertools import cycle
from typing import Any, cast
from typing import Optional as Optional

import pytest
from pydantic import BaseModel
Expand Down

0 comments on commit 3a291b1

Please sign in to comment.