The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
langchain: Add ruff rules PIE (#31880)
Christophe Bornet53c75abba2bc
diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.pyindex 7f2c708ead..129e443c4d 100644--- a/libs/langchain/langchain/agents/agent.py+++ b/libs/langchain/langchain/agents/agent.py@@ -449,7 +449,7 @@ class RunnableAgent(BaseSingleActionAgent):Returns:Action specifying what tool to use."""- inputs = {**kwargs, **{"intermediate_steps": intermediate_steps}}+ inputs = {**kwargs, "intermediate_steps": intermediate_steps}final_output: Any = Noneif self.stream_runnable:# Use streaming to make sure that the underlying LLM is invoked in a@@ -488,7 +488,7 @@ class RunnableAgent(BaseSingleActionAgent):Returns:Action specifying what tool to use."""- inputs = {**kwargs, **{"intermediate_steps": intermediate_steps}}+ inputs = {**kwargs, "intermediate_steps": intermediate_steps}final_output: Any = Noneif self.stream_runnable:# Use streaming to make sure that the underlying LLM is invoked in a@@ -565,7 +565,7 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):Returns:Action specifying what tool to use."""- inputs = {**kwargs, **{"intermediate_steps": intermediate_steps}}+ inputs = {**kwargs, "intermediate_steps": intermediate_steps}final_output: Any = Noneif self.stream_runnable:# Use streaming to make sure that the underlying LLM is invoked in a@@ -604,7 +604,7 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):Returns:Action specifying what tool to use."""- inputs = {**kwargs, **{"intermediate_steps": intermediate_steps}}+ inputs = {**kwargs, "intermediate_steps": intermediate_steps}final_output: Any = Noneif self.stream_runnable:# Use streaming to make sure that the underlying LLM is invoked in a@@ -907,8 +907,6 @@ class Agent(BaseSingleActionAgent):tools: Tools to use."""- pass-@classmethod@abstractmethoddef _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:diff --git a/libs/langchain/langchain/chains/combine_documents/map_reduce.py b/libs/langchain/langchain/chains/combine_documents/map_reduce.pyindex 42be28cc63..166d5624f2 100644--- a/libs/langchain/langchain/chains/combine_documents/map_reduce.py+++ b/libs/langchain/langchain/chains/combine_documents/map_reduce.py@@ -270,7 +270,7 @@ class MapReduceDocumentsChain(BaseCombineDocumentsChain):"""map_results = await self.llm_chain.aapply(# FYI - this is parallelized and so it is fast.- [{**{self.document_variable_name: d.page_content}, **kwargs} for d in docs],+ [{self.document_variable_name: d.page_content, **kwargs} for d in docs],callbacks=callbacks,)question_result_key = self.llm_chain.output_keydiff --git a/libs/langchain/langchain/chains/combine_documents/map_rerank.py b/libs/langchain/langchain/chains/combine_documents/map_rerank.pyindex 7cd90f87a6..8692f1ff99 100644--- a/libs/langchain/langchain/chains/combine_documents/map_rerank.py+++ b/libs/langchain/langchain/chains/combine_documents/map_rerank.py@@ -182,7 +182,7 @@ class MapRerankDocumentsChain(BaseCombineDocumentsChain):"""results = self.llm_chain.apply_and_parse(# FYI - this is parallelized and so it is fast.- [{**{self.document_variable_name: d.page_content}, **kwargs} for d in docs],+ [{self.document_variable_name: d.page_content, **kwargs} for d in docs],callbacks=callbacks,)return self._process_results(docs, results)@@ -206,7 +206,7 @@ class MapRerankDocumentsChain(BaseCombineDocumentsChain):"""results = await self.llm_chain.aapply_and_parse(# FYI - this is parallelized and so it is fast.- [{**{self.document_variable_name: d.page_content}, **kwargs} for d in docs],+ [{self.document_variable_name: d.page_content, **kwargs} for d in docs],callbacks=callbacks,)return self._process_results(docs, results)diff --git a/libs/langchain/langchain/memory/entity.py b/libs/langchain/langchain/memory/entity.pyindex 982be3645c..632c171474 100644--- a/libs/langchain/langchain/memory/entity.py+++ b/libs/langchain/langchain/memory/entity.py@@ -40,27 +40,22 @@ class BaseEntityStore(BaseModel, ABC):@abstractmethoddef get(self, key: str, default: Optional[str] = None) -> Optional[str]:"""Get entity value from store."""- pass@abstractmethoddef set(self, key: str, value: Optional[str]) -> None:"""Set entity value in store."""- pass@abstractmethoddef delete(self, key: str) -> None:"""Delete entity value from store."""- pass@abstractmethoddef exists(self, key: str) -> bool:"""Check if entity exists in store."""- pass@abstractmethoddef clear(self) -> None:"""Delete all entities from store."""- pass@deprecated(diff --git a/libs/langchain/langchain/memory/readonly.py b/libs/langchain/langchain/memory/readonly.pyindex 0e03c924a5..48e23d08fa 100644--- a/libs/langchain/langchain/memory/readonly.py+++ b/libs/langchain/langchain/memory/readonly.py@@ -19,8 +19,6 @@ class ReadOnlySharedMemory(BaseMemory):def save_context(self, inputs: dict[str, Any], outputs: dict[str, str]) -> None:"""Nothing should be saved or changed"""- passdef clear(self) -> None:"""Nothing to clear, got a memory like a vault."""- passdiff --git a/libs/langchain/langchain/memory/simple.py b/libs/langchain/langchain/memory/simple.pyindex c6da1f8979..5524cabfec 100644--- a/libs/langchain/langchain/memory/simple.py+++ b/libs/langchain/langchain/memory/simple.py@@ -19,8 +19,6 @@ class SimpleMemory(BaseMemory):def save_context(self, inputs: dict[str, Any], outputs: dict[str, str]) -> None:"""Nothing should be saved or changed, my memory is set in stone."""- passdef clear(self) -> None:"""Nothing to clear, got a memory like a vault."""- passdiff --git a/libs/langchain/langchain/smith/evaluation/runner_utils.py b/libs/langchain/langchain/smith/evaluation/runner_utils.pyindex 5c7f608446..c86b41f512 100644--- a/libs/langchain/langchain/smith/evaluation/runner_utils.py+++ b/libs/langchain/langchain/smith/evaluation/runner_utils.py@@ -98,10 +98,8 @@ class TestResult(dict):to_drop = [colfor col in df.columns- if col.startswith("inputs.")- or col.startswith("outputs.")+ if col.startswith(("inputs.", "outputs.", "reference"))or col in {"input", "output"}- or col.startswith("reference")]return df.describe(include="all").drop(to_drop, axis=1)diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.tomlindex ef475d0840..39dea93142 100644--- a/libs/langchain/pyproject.toml+++ b/libs/langchain/pyproject.toml@@ -143,7 +143,7 @@ ignore-regex = ".*(Stati Uniti|Tense=Pres).*"ignore-words-list = "momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia,nin"[tool.ruff.lint]-select = ["E", "F", "I", "PGH003", "T201", "D", "UP", "S", "W"]+select = ["E", "F", "I", "PGH003", "PIE", "T201", "D", "UP", "S", "W"]pydocstyle.convention = "google"pyupgrade.keep-runtime-typing = truediff --git a/libs/langchain/tests/integration_tests/test_compile.py b/libs/langchain/tests/integration_tests/test_compile.pyindex 33ecccdfa0..f315e45f52 100644--- a/libs/langchain/tests/integration_tests/test_compile.py+++ b/libs/langchain/tests/integration_tests/test_compile.py@@ -4,4 +4,3 @@ import pytest@pytest.mark.compiledef test_placeholder() -> None:"""Used for compiling integration tests without running any real tests."""- pass