Skip to content

The agent engineering platform.

core: Add ruff rules for PIE (#26939)

Christophe Bornetf4e738bb4098
diff --git a/libs/core/langchain_core/callbacks/streaming_stdout.py b/libs/core/langchain_core/callbacks/streaming_stdout.py
index 4ae0bcb419..7f6fa57908 100644
--- a/libs/core/langchain_core/callbacks/streaming_stdout.py
+++ b/libs/core/langchain_core/callbacks/streaming_stdout.py
@@ -112,7 +112,6 @@ class StreamingStdOutCallbackHandler(BaseCallbackHandler):
action (AgentAction): The agent action.
**kwargs (Any): Additional keyword arguments.
"""
- pass
def on_tool_end(self, output: Any, **kwargs: Any) -> None:
"""Run when tool ends running.
diff --git a/libs/core/langchain_core/language_models/chat_models.py b/libs/core/langchain_core/language_models/chat_models.py
index 57a0cd37c1..7d46f490bb 100644
--- a/libs/core/langchain_core/language_models/chat_models.py
+++ b/libs/core/langchain_core/language_models/chat_models.py
@@ -357,7 +357,7 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
stop: Optional[list[str]] = None,
**kwargs: Any,
) -> Iterator[BaseMessageChunk]:
- if not self._should_stream(async_api=False, **{**kwargs, **{"stream": True}}):
+ if not self._should_stream(async_api=False, **{**kwargs, "stream": True}):
# model doesn't implement streaming, so use default implementation
yield cast(
BaseMessageChunk, self.invoke(input, config=config, stop=stop, **kwargs)
@@ -427,7 +427,7 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
stop: Optional[list[str]] = None,
**kwargs: Any,
) -> AsyncIterator[BaseMessageChunk]:
- if not self._should_stream(async_api=True, **{**kwargs, **{"stream": True}}):
+ if not self._should_stream(async_api=True, **{**kwargs, "stream": True}):
# No async or sync stream is implemented, so fall back to ainvoke
yield cast(
BaseMessageChunk,
@@ -550,7 +550,7 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
def _get_llm_string(self, stop: Optional[list[str]] = None, **kwargs: Any) -> str:
if self.is_lc_serializable():
- params = {**kwargs, **{"stop": stop}}
+ params = {**kwargs, "stop": stop}
param_string = str(sorted(params.items()))
# This code is not super efficient as it goes back and forth between
# json and dict.
diff --git a/libs/core/langchain_core/prompts/chat.py b/libs/core/langchain_core/prompts/chat.py
index ab4a401057..7a721daa1e 100644
--- a/libs/core/langchain_core/prompts/chat.py
+++ b/libs/core/langchain_core/prompts/chat.py
@@ -1007,11 +1007,9 @@ class ChatPromptTemplate(BaseChatPromptTemplate):
input_vars.update(_message.input_variables)
kwargs = {
- **{
- "input_variables": sorted(input_vars),
- "optional_variables": sorted(optional_variables),
- "partial_variables": partial_vars,
- },
+ "input_variables": sorted(input_vars),
+ "optional_variables": sorted(optional_variables),
+ "partial_variables": partial_vars,
**kwargs,
}
cast(type[ChatPromptTemplate], super()).__init__(messages=_messages, **kwargs)
diff --git a/libs/core/langchain_core/runnables/config.py b/libs/core/langchain_core/runnables/config.py
index ab1c8641b9..b1d40bd551 100644
--- a/libs/core/langchain_core/runnables/config.py
+++ b/libs/core/langchain_core/runnables/config.py
@@ -36,8 +36,6 @@ else:
class EmptyDict(TypedDict, total=False):
"""Empty dict type."""
- pass
-
class RunnableConfig(TypedDict, total=False):
"""Configuration for a Runnable."""
diff --git a/libs/core/langchain_core/runnables/configurable.py b/libs/core/langchain_core/runnables/configurable.py
index bfd00c1de7..5c56b8ef50 100644
--- a/libs/core/langchain_core/runnables/configurable.py
+++ b/libs/core/langchain_core/runnables/configurable.py
@@ -457,8 +457,6 @@ RunnableConfigurableFields.model_rebuild()
class StrEnum(str, enum.Enum):
"""String enum."""
- pass
-
_enums_for_spec: WeakValueDictionary[
Union[
diff --git a/libs/core/langchain_core/runnables/fallbacks.py b/libs/core/langchain_core/runnables/fallbacks.py
index d331e3567e..647c08b3e2 100644
--- a/libs/core/langchain_core/runnables/fallbacks.py
+++ b/libs/core/langchain_core/runnables/fallbacks.py
@@ -619,7 +619,8 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
return self.__class__(
**{
**self.model_dump(),
- **{"runnable": new_runnable, "fallbacks": new_fallbacks},
+ "runnable": new_runnable,
+ "fallbacks": new_fallbacks,
}
)
diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py
index 1fc670cc27..d8f63c069e 100644
--- a/libs/core/langchain_core/tools/base.py
+++ b/libs/core/langchain_core/tools/base.py
@@ -320,8 +320,6 @@ class ToolException(Exception): # noqa: N818
to the agent as observation, and printed in red on the console.
"""
- pass
-
class BaseTool(RunnableSerializable[Union[str, dict, ToolCall], Any]):
"""Interface LangChain tools must implement."""
diff --git a/libs/core/langchain_core/tracers/base.py b/libs/core/langchain_core/tracers/base.py
index a31e6d9ede..ba8c90f2c9 100644
--- a/libs/core/langchain_core/tracers/base.py
+++ b/libs/core/langchain_core/tracers/base.py
@@ -850,7 +850,6 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
async def _on_run_create(self, run: Run) -> None:
"""Process a run upon creation."""
- pass
async def _on_run_update(self, run: Run) -> None:
"""Process a run upon update."""
diff --git a/libs/core/langchain_core/tracers/event_stream.py b/libs/core/langchain_core/tracers/event_stream.py
index d374a3cd3f..03d7bc9561 100644
--- a/libs/core/langchain_core/tracers/event_stream.py
+++ b/libs/core/langchain_core/tracers/event_stream.py
@@ -829,7 +829,6 @@ async def _astream_events_implementation_v1(
inputs = log_entry["inputs"]
if inputs is not None:
data["input"] = inputs
- pass
if event_type == "end":
inputs = log_entry["inputs"]
diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.py
index f88eb40b38..f8227a06a6 100644
--- a/libs/core/langchain_core/utils/function_calling.py
+++ b/libs/core/langchain_core/utils/function_calling.py
@@ -561,7 +561,7 @@ def _parse_google_docstring(
if block.startswith("Args:"):
args_block = block
break
- elif block.startswith("Returns:") or block.startswith("Example:"):
+ elif block.startswith(("Returns:", "Example:")):
# Don't break in case Args come after
past_descriptors = True
elif not past_descriptors:
diff --git a/libs/core/langchain_core/utils/mustache.py b/libs/core/langchain_core/utils/mustache.py
index c517233a36..a64ec346c5 100644
--- a/libs/core/langchain_core/utils/mustache.py
+++ b/libs/core/langchain_core/utils/mustache.py
@@ -32,8 +32,6 @@ _LAST_TAG_LINE = None
class ChevronError(SyntaxError):
"""Custom exception for Chevron errors."""
- pass
-
#
# Helper functions
diff --git a/libs/core/langchain_core/utils/utils.py b/libs/core/langchain_core/utils/utils.py
index a90eba11b9..8236e7fba1 100644
--- a/libs/core/langchain_core/utils/utils.py
+++ b/libs/core/langchain_core/utils/utils.py
@@ -268,8 +268,6 @@ def convert_to_secret_str(value: Union[SecretStr, str]) -> SecretStr:
class _NoDefaultType:
"""Type to indicate no default value is provided."""
- pass
-
_NoDefault = _NoDefaultType()
diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml
index a731811d08..9bb2146b7b 100644
--- a/libs/core/pyproject.toml
+++ b/libs/core/pyproject.toml
@@ -44,7 +44,7 @@ python = ">=3.12.4"
[tool.poetry.extras]
[tool.ruff.lint]
-select = [ "B", "C4", "E", "F", "I", "N", "T201", "UP",]
+select = [ "B", "C4", "E", "F", "I", "N", "PIE", "T201", "UP",]
ignore = [ "UP007",]
[tool.coverage.run]
diff --git a/libs/core/tests/integration_tests/test_compile.py b/libs/core/tests/integration_tests/test_compile.py
index 33ecccdfa0..f315e45f52 100644
--- a/libs/core/tests/integration_tests/test_compile.py
+++ b/libs/core/tests/integration_tests/test_compile.py
@@ -4,4 +4,3 @@ import pytest
@pytest.mark.compile
def test_placeholder() -> None:
"""Used for compiling integration tests without running any real tests."""
- pass
diff --git a/libs/core/tests/unit_tests/_api/test_beta_decorator.py b/libs/core/tests/unit_tests/_api/test_beta_decorator.py
index 07480b6831..40465813d2 100644
--- a/libs/core/tests/unit_tests/_api/test_beta_decorator.py
+++ b/libs/core/tests/unit_tests/_api/test_beta_decorator.py
@@ -68,7 +68,6 @@ async def beta_async_function() -> str:
class ClassWithBetaMethods:
def __init__(self) -> None:
"""original doc"""
- pass
@beta()
def beta_method(self) -> str:
@@ -244,7 +243,6 @@ def test_whole_class_beta() -> None:
class BetaClass:
def __init__(self) -> None:
"""original doc"""
- pass
@beta()
def beta_method(self) -> str:
diff --git a/libs/core/tests/unit_tests/_api/test_deprecation.py b/libs/core/tests/unit_tests/_api/test_deprecation.py
index 726e8f9f9d..06ffa55a8d 100644
--- a/libs/core/tests/unit_tests/_api/test_deprecation.py
+++ b/libs/core/tests/unit_tests/_api/test_deprecation.py
@@ -88,7 +88,6 @@ async def deprecated_async_function() -> str:
class ClassWithDeprecatedMethods:
def __init__(self) -> None:
"""original doc"""
- pass
@deprecated(since="2.0.0", removal="3.0.0")
def deprecated_method(self) -> str:
@@ -268,7 +267,6 @@ def test_whole_class_deprecation() -> None:
class DeprecatedClass:
def __init__(self) -> None:
"""original doc"""
- pass
@deprecated(since="2.0.0", removal="3.0.0")
def deprecated_method(self) -> str:
@@ -311,7 +309,6 @@ def test_whole_class_inherited_deprecation() -> None:
class DeprecatedClass:
def __init__(self) -> None:
"""original doc"""
- pass
@deprecated(since="2.0.0", removal="3.0.0")
def deprecated_method(self) -> str:
@@ -324,7 +321,6 @@ def test_whole_class_inherited_deprecation() -> None:
def __init__(self) -> None:
"""original doc"""
- pass
@deprecated(since="2.2.0", removal="3.2.0")
def deprecated_method(self) -> str:
diff --git a/libs/core/tests/unit_tests/language_models/chat_models/test_base.py b/libs/core/tests/unit_tests/language_models/chat_models/test_base.py
index 99d74e47cc..85f6d5bee1 100644
--- a/libs/core/tests/unit_tests/language_models/chat_models/test_base.py
+++ b/libs/core/tests/unit_tests/language_models/chat_models/test_base.py
@@ -107,7 +107,7 @@ async def test_stream_error_callback() -> None:
else:
assert llm_result.generations[0][0].text == message[:i]
- for i in range(0, 2):
+ for i in range(2):
llm = FakeListChatModel(
responses=[message],
error_on_chunk_number=i,
diff --git a/libs/core/tests/unit_tests/language_models/llms/test_base.py b/libs/core/tests/unit_tests/language_models/llms/test_base.py
index e610838d69..9c995f924c 100644
--- a/libs/core/tests/unit_tests/language_models/llms/test_base.py
+++ b/libs/core/tests/unit_tests/language_models/llms/test_base.py
@@ -105,7 +105,7 @@ async def test_stream_error_callback() -> None:
else:
assert llm_result.generations[0][0].text == message[:i]
- for i in range(0, 2):
+ for i in range(2):
llm = FakeStreamingListLLM(
responses=[message],
error_on_chunk_number=i,
diff --git a/libs/core/tests/unit_tests/test_messages.py b/libs/core/tests/unit_tests/test_messages.py
index 2743783ca8..9d659d6bd8 100644
--- a/libs/core/tests/unit_tests/test_messages.py
+++ b/libs/core/tests/unit_tests/test_messages.py
@@ -429,16 +429,12 @@ def test_message_chunk_to_message() -> None:
expected = AIMessage(
content="I am",
tool_calls=[
- create_tool_call(**{"name": "tool1", "args": {"a": 1}, "id": "1"}), # type: ignore[arg-type]
- create_tool_call(**{"name": "tool2", "args": {}, "id": "2"}), # type: ignore[arg-type]
+ create_tool_call(name="tool1", args={"a": 1}, id="1"), # type: ignore[arg-type]
+ create_tool_call(name="tool2", args={}, id="2"), # type: ignore[arg-type]
],
invalid_tool_calls=[
- create_invalid_tool_call(
- **{"name": "tool3", "args": None, "id": "3", "error": None}
- ),
- create_invalid_tool_call(
- **{"name": "tool4", "args": "abc", "id": "4", "error": None}
- ),
+ create_invalid_tool_call(name="tool3", args=None, id="3", error=None),
+ create_invalid_tool_call(name="tool4", args="abc", id="4", error=None),
],
)
assert message_chunk_to_message(chunk) == expected
diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py
index dc70ef9dbb..a61cead53c 100644
--- a/libs/core/tests/unit_tests/test_tools.py
+++ b/libs/core/tests/unit_tests/test_tools.py
@@ -357,7 +357,6 @@ def test_structured_tool_types_parsed_pydantic_mixed() -> None:
some_base_model: SomeBaseModel, another_base_model: AnotherBaseModel
) -> None:
"""Return the arguments directly."""
- pass
def test_base_tool_inheritance_base_schema() -> None:
diff --git a/libs/core/tests/unit_tests/utils/test_function_calling.py b/libs/core/tests/unit_tests/utils/test_function_calling.py
index 6f09624d74..01943ab4db 100644
--- a/libs/core/tests/unit_tests/utils/test_function_calling.py
+++ b/libs/core/tests/unit_tests/utils/test_function_calling.py
@@ -54,7 +54,6 @@ def annotated_function() -> Callable:
arg2: ExtensionsAnnotated[Literal["bar", "baz"], "one of 'bar', 'baz'"],
) -> None:
"""dummy function"""
- pass
return dummy_function
@@ -68,7 +67,6 @@ def function() -> Callable:
arg1: foo
arg2: one of 'bar', 'baz'
"""
- pass
return dummy_function
@@ -220,7 +218,6 @@ class Dummy:
arg1: foo
arg2: one of 'bar', 'baz'
"""
- pass
class DummyWithClassMethod:
@@ -232,7 +229,6 @@ class DummyWithClassMethod:
arg1: foo
arg2: one of 'bar', 'baz'
"""
- pass
def test_convert_to_openai_function(
@@ -334,7 +330,6 @@ def test_convert_to_openai_function_nested_v2() -> None:
def my_function(arg1: NestedV2) -> None:
"""dummy function"""
- pass
convert_to_openai_function(my_function)
@@ -348,7 +343,6 @@ def test_convert_to_openai_function_nested() -> None:
def my_function(arg1: Nested) -> None:
"""dummy function"""
- pass
expected = {
"name": "my_function",
@@ -386,7 +380,6 @@ def test_convert_to_openai_function_nested_strict() -> None:
def my_function(arg1: Nested) -> None:
"""dummy function"""
- pass
expected = {
"name": "my_function",
@@ -429,7 +422,6 @@ def test_function_optional_param() -> None:
c: Optional[list[Optional[str]]],
) -> None:
"""A test function"""
- pass
func = convert_to_openai_function(func5)
req = func["parameters"]["required"]
@@ -439,7 +431,6 @@ def test_function_optional_param() -> None:
def test_function_no_params() -> None:
def nullary_function() -> None:
"""nullary function"""
- pass
func = convert_to_openai_function(nullary_function)
req = func["parameters"].get("required")
@@ -781,7 +772,6 @@ def test_convert_union_type_py_39() -> None:
@tool
def magic_function(input: int | float) -> str:
"""Compute a magic function."""
- pass
result = convert_to_openai_function(magic_function)
assert result["parameters"]["properties"]["input"] == {