Skip to content

Commit ccc3d32

Browse files
authored
core: Add ruff rules for Pylint PLC (Convention) and PLE (Errors) (#29286)
See https://docs.astral.sh/ruff/rules/#pylint-pl
1 parent fe0fd9d commit ccc3d32

File tree

16 files changed

+79
-80
lines changed

16 files changed

+79
-80
lines changed

libs/core/langchain_core/callbacks/manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,9 +2244,6 @@ async def on_chain_error(
22442244
T = TypeVar("T", CallbackManager, AsyncCallbackManager)
22452245

22462246

2247-
H = TypeVar("H", bound=BaseCallbackHandler, covariant=True)
2248-
2249-
22502247
def _configure(
22512248
callback_manager_cls: type[T],
22522249
inheritable_callbacks: Callbacks = None,

libs/core/langchain_core/document_loaders/blob_loaders.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from typing import TYPE_CHECKING
1212

1313
# Re-export Blob and PathLike for backwards compatibility
14-
from langchain_core.documents.base import Blob as Blob
15-
from langchain_core.documents.base import PathLike as PathLike
14+
from langchain_core.documents.base import Blob, PathLike
1615

1716
if TYPE_CHECKING:
1817
from collections.abc import Iterable

libs/core/langchain_core/messages/modifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, id: str, **kwargs: Any) -> None:
2525
msg = "RemoveMessage does not support 'content' field."
2626
raise ValueError(msg)
2727

28-
return super().__init__("", id=id, **kwargs)
28+
super().__init__("", id=id, **kwargs)
2929

3030

3131
RemoveMessage.model_rebuild()

libs/core/langchain_core/output_parsers/list.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from collections import deque
99
from io import StringIO
1010
from typing import TYPE_CHECKING, TypeVar, Union
11-
from typing import Optional as Optional
1211

1312
from typing_extensions import override
1413

libs/core/langchain_core/output_parsers/string.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""String output parser."""
22

3-
from typing import Optional as Optional
4-
53
from langchain_core.output_parsers.transform import BaseTransformOutputParser
64

75

libs/core/langchain_core/prompts/pipeline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""[DEPRECATED] Pipeline prompt template."""
22

33
from typing import Any
4-
from typing import Optional as Optional
54

65
from pydantic import model_validator
76

libs/core/langchain_core/runnables/configurable.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
import enum
66
import threading
77
from abc import abstractmethod
8-
from collections.abc import AsyncIterator, Iterator, Sequence
9-
from collections.abc import Mapping as Mapping
8+
from collections.abc import (
9+
AsyncIterator,
10+
Iterator,
11+
Mapping, # noqa: F401 Needed by pydantic
12+
Sequence,
13+
)
1014
from functools import wraps
1115
from typing import (
1216
TYPE_CHECKING,

libs/core/langchain_core/runnables/graph_mermaid.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ def add_subgraph(edges: list[Edge], prefix: str) -> None:
195195
)
196196

197197
# Recursively add nested subgraphs
198-
for nested_prefix in edge_groups:
198+
for nested_prefix, edges_ in edge_groups.items():
199199
if not nested_prefix.startswith(prefix + ":") or nested_prefix == prefix:
200200
continue
201201
# only go to first level subgraphs
202202
if ":" in nested_prefix[len(prefix) + 1 :]:
203203
continue
204-
add_subgraph(edge_groups[nested_prefix], nested_prefix)
204+
add_subgraph(edges_, nested_prefix)
205205

206206
if prefix and not self_loop:
207207
mermaid_graph += "\tend\n"
@@ -210,20 +210,20 @@ def add_subgraph(edges: list[Edge], prefix: str) -> None:
210210
add_subgraph(edge_groups.get("", []), "")
211211

212212
# Add remaining subgraphs with edges
213-
for prefix in edge_groups:
213+
for prefix, edges_ in edge_groups.items():
214214
if ":" in prefix or prefix == "":
215215
continue
216-
add_subgraph(edge_groups[prefix], prefix)
216+
add_subgraph(edges_, prefix)
217217
seen_subgraphs.add(prefix)
218218

219219
# Add empty subgraphs (subgraphs with no internal edges)
220220
if with_styles:
221-
for prefix in subgraph_nodes:
221+
for prefix, subgraph_node in subgraph_nodes.items():
222222
if ":" not in prefix and prefix not in seen_subgraphs:
223223
mermaid_graph += f"\tsubgraph {prefix}\n"
224224

225225
# Add nodes that belong to this subgraph
226-
for key, node in subgraph_nodes[prefix].items():
226+
for key, node in subgraph_node.items():
227227
mermaid_graph += render_node(key, node)
228228

229229
mermaid_graph += "\tend\n"

libs/core/langchain_core/runnables/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing_extensions import TypeGuard, override
2424

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

2828
if TYPE_CHECKING:
2929
from collections.abc import (
@@ -38,9 +38,9 @@
3838

3939
from langchain_core.runnables.schema import StreamEvent
4040

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

4545

4646
async def gated_coro(semaphore: asyncio.Semaphore, coro: Coroutine) -> Any:

libs/core/langchain_core/tools/__init__.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,51 @@
2020
from __future__ import annotations
2121

2222
from langchain_core.tools.base import (
23-
FILTERED_ARGS as FILTERED_ARGS,
24-
)
25-
from langchain_core.tools.base import (
26-
ArgsSchema as ArgsSchema,
27-
)
28-
from langchain_core.tools.base import (
29-
BaseTool as BaseTool,
30-
)
31-
from langchain_core.tools.base import (
32-
BaseToolkit as BaseToolkit,
33-
)
34-
from langchain_core.tools.base import (
35-
InjectedToolArg as InjectedToolArg,
36-
)
37-
from langchain_core.tools.base import InjectedToolCallId as InjectedToolCallId
38-
from langchain_core.tools.base import SchemaAnnotationError as SchemaAnnotationError
39-
from langchain_core.tools.base import (
40-
ToolException as ToolException,
41-
)
42-
from langchain_core.tools.base import (
43-
_get_runnable_config_param as _get_runnable_config_param,
44-
)
45-
from langchain_core.tools.base import (
46-
create_schema_from_function as create_schema_from_function,
23+
FILTERED_ARGS,
24+
ArgsSchema,
25+
BaseTool,
26+
BaseToolkit,
27+
InjectedToolArg,
28+
InjectedToolCallId,
29+
SchemaAnnotationError,
30+
ToolException,
31+
_get_runnable_config_param,
32+
create_schema_from_function,
4733
)
4834
from langchain_core.tools.convert import (
49-
convert_runnable_to_tool as convert_runnable_to_tool,
50-
)
51-
from langchain_core.tools.convert import tool as tool
52-
from langchain_core.tools.render import ToolsRenderer as ToolsRenderer
53-
from langchain_core.tools.render import (
54-
render_text_description as render_text_description,
35+
convert_runnable_to_tool,
36+
tool,
5537
)
5638
from langchain_core.tools.render import (
57-
render_text_description_and_args as render_text_description_and_args,
39+
ToolsRenderer,
40+
render_text_description,
41+
render_text_description_and_args,
5842
)
59-
from langchain_core.tools.retriever import RetrieverInput as RetrieverInput
6043
from langchain_core.tools.retriever import (
61-
create_retriever_tool as create_retriever_tool,
44+
RetrieverInput,
45+
create_retriever_tool,
6246
)
63-
from langchain_core.tools.simple import Tool as Tool
64-
from langchain_core.tools.structured import StructuredTool as StructuredTool
47+
from langchain_core.tools.simple import Tool
48+
from langchain_core.tools.structured import StructuredTool
49+
50+
__all__ = [
51+
"ArgsSchema",
52+
"BaseTool",
53+
"BaseToolkit",
54+
"FILTERED_ARGS",
55+
"SchemaAnnotationError",
56+
"ToolException",
57+
"InjectedToolArg",
58+
"InjectedToolCallId",
59+
"_get_runnable_config_param",
60+
"create_schema_from_function",
61+
"convert_runnable_to_tool",
62+
"tool",
63+
"ToolsRenderer",
64+
"render_text_description",
65+
"render_text_description_and_args",
66+
"RetrieverInput",
67+
"create_retriever_tool",
68+
"Tool",
69+
"StructuredTool",
70+
]

libs/core/langchain_core/utils/mustache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ def _html_escape(string: str) -> str:
324324

325325
# & must be handled first
326326
string = string.replace("&", "&")
327-
for char in html_codes:
328-
string = string.replace(char, html_codes[char])
327+
for char, code in html_codes.items():
328+
string = string.replace(char, code)
329329
return string
330330

331331

libs/core/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ ignore = [
101101
"FBT002",
102102
"FIX",
103103
"PGH",
104-
"PLC",
105-
"PLE",
106104
"PLR",
107105
"PYI",
108106
"RET",

libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
from typing import Optional as Optional
32

43
import pytest
54
from blockbuster import BlockBuster

libs/core/tests/unit_tests/output_parsers/test_base_parsers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Module to test base parser implementations."""
22

3-
from typing import Optional as Optional
4-
53
from langchain_core.exceptions import OutputParserException
64
from langchain_core.language_models import GenericFakeChatModel
75
from langchain_core.messages import AIMessage

libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections.abc import AsyncIterator, Sequence
66
from itertools import cycle
77
from typing import Any, cast
8-
from typing import Optional as Optional
98

109
import pytest
1110
from pydantic import BaseModel

0 commit comments

Comments
 (0)