Skip to content

Commit ed35372

Browse files
cbornetmdrxy
andauthored
langchain: Add ruff rules FBT (#31885)
* Fixed for private functions and in tests * Added noqa escapes for public functions See https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt Co-authored-by: Mason Daugherty <[email protected]>
1 parent 56bbfd9 commit ed35372

File tree

28 files changed

+77
-53
lines changed

28 files changed

+77
-53
lines changed

libs/langchain/langchain/agents/agent_toolkits/conversational_retrieval/openai_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def _get_default_system_message() -> SystemMessage:
2727
def create_conversational_retrieval_agent(
2828
llm: BaseLanguageModel,
2929
tools: list[BaseTool],
30-
remember_intermediate_steps: bool = True,
30+
remember_intermediate_steps: bool = True, # noqa: FBT001,FBT002
3131
memory_key: str = "chat_history",
3232
system_message: Optional[SystemMessage] = None,
33-
verbose: bool = False,
33+
verbose: bool = False, # noqa: FBT001,FBT002
3434
max_token_limit: int = 2000,
3535
**kwargs: Any,
3636
) -> AgentExecutor:

libs/langchain/langchain/agents/agent_toolkits/vectorstore/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_vectorstore_agent(
3535
toolkit: VectorStoreToolkit,
3636
callback_manager: Optional[BaseCallbackManager] = None,
3737
prefix: str = PREFIX,
38-
verbose: bool = False,
38+
verbose: bool = False, # noqa: FBT001,FBT002
3939
agent_executor_kwargs: Optional[dict[str, Any]] = None,
4040
**kwargs: Any,
4141
) -> AgentExecutor:
@@ -128,7 +128,7 @@ def create_vectorstore_router_agent(
128128
toolkit: VectorStoreRouterToolkit,
129129
callback_manager: Optional[BaseCallbackManager] = None,
130130
prefix: str = ROUTER_PREFIX,
131-
verbose: bool = False,
131+
verbose: bool = False, # noqa: FBT001,FBT002
132132
agent_executor_kwargs: Optional[dict[str, Any]] = None,
133133
**kwargs: Any,
134134
) -> AgentExecutor:

libs/langchain/langchain/agents/json_chat/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_json_chat_agent(
1616
llm: BaseLanguageModel,
1717
tools: Sequence[BaseTool],
1818
prompt: ChatPromptTemplate,
19-
stop_sequence: Union[bool, list[str]] = True,
19+
stop_sequence: Union[bool, list[str]] = True, # noqa: FBT001,FBT002
2020
tools_renderer: ToolsRenderer = render_text_description,
2121
template_tool_response: str = TEMPLATE_TOOL_RESPONSE,
2222
) -> Runnable:

libs/langchain/langchain/agents/openai_functions_agent/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def plan(
9797
self,
9898
intermediate_steps: list[tuple[AgentAction, str]],
9999
callbacks: Callbacks = None,
100-
with_functions: bool = True,
100+
with_functions: bool = True, # noqa: FBT001,FBT002
101101
**kwargs: Any,
102102
) -> Union[AgentAction, AgentFinish]:
103103
"""Given input, decided what to do.

libs/langchain/langchain/agents/openai_tools/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def create_openai_tools_agent(
1717
llm: BaseLanguageModel,
1818
tools: Sequence[BaseTool],
1919
prompt: ChatPromptTemplate,
20-
strict: Optional[bool] = None,
20+
strict: Optional[bool] = None, # noqa: FBT001
2121
) -> Runnable:
2222
"""Create an agent that uses OpenAI tools.
2323

libs/langchain/langchain/chains/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ def raise_callback_manager_deprecation(cls, values: dict) -> Any:
254254

255255
@field_validator("verbose", mode="before")
256256
@classmethod
257-
def set_verbose(cls, verbose: Optional[bool]) -> bool:
257+
def set_verbose(
258+
cls,
259+
verbose: Optional[bool], # noqa: FBT001
260+
) -> bool:
258261
"""Set the chain verbosity.
259262
260263
Defaults to the global setting if not specified by the user.
@@ -353,7 +356,7 @@ async def _acall(
353356
def __call__(
354357
self,
355358
inputs: Union[dict[str, Any], Any],
356-
return_only_outputs: bool = False,
359+
return_only_outputs: bool = False, # noqa: FBT001,FBT002
357360
callbacks: Callbacks = None,
358361
*,
359362
tags: Optional[list[str]] = None,
@@ -404,7 +407,7 @@ def __call__(
404407
async def acall(
405408
self,
406409
inputs: Union[dict[str, Any], Any],
407-
return_only_outputs: bool = False,
410+
return_only_outputs: bool = False, # noqa: FBT001,FBT002
408411
callbacks: Callbacks = None,
409412
*,
410413
tags: Optional[list[str]] = None,
@@ -454,7 +457,7 @@ def prep_outputs(
454457
self,
455458
inputs: dict[str, str],
456459
outputs: dict[str, str],
457-
return_only_outputs: bool = False,
460+
return_only_outputs: bool = False, # noqa: FBT001,FBT002
458461
) -> dict[str, str]:
459462
"""Validate and prepare chain outputs, and save info about this run to memory.
460463
@@ -479,7 +482,7 @@ async def aprep_outputs(
479482
self,
480483
inputs: dict[str, str],
481484
outputs: dict[str, str],
482-
return_only_outputs: bool = False,
485+
return_only_outputs: bool = False, # noqa: FBT001,FBT002
483486
) -> dict[str, str]:
484487
"""Validate and prepare chain outputs, and save info about this run to memory.
485488

libs/langchain/langchain/chains/conversational_retrieval/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def from_llm(
420420
retriever: BaseRetriever,
421421
condense_question_prompt: BasePromptTemplate = CONDENSE_QUESTION_PROMPT,
422422
chain_type: str = "stuff",
423-
verbose: bool = False,
423+
verbose: bool = False, # noqa: FBT001,FBT002
424424
condense_question_llm: Optional[BaseLanguageModel] = None,
425425
combine_docs_chain_kwargs: Optional[dict] = None,
426426
callbacks: Callbacks = None,

libs/langchain/langchain/chains/llm_summarization_checker/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def _load_sequential_chain(
3030
check_assertions_prompt: PromptTemplate,
3131
revised_summary_prompt: PromptTemplate,
3232
are_all_true_prompt: PromptTemplate,
33+
*,
3334
verbose: bool = False,
3435
) -> SequentialChain:
3536
return SequentialChain(
@@ -188,7 +189,7 @@ def from_llm(
188189
check_assertions_prompt: PromptTemplate = CHECK_ASSERTIONS_PROMPT,
189190
revised_summary_prompt: PromptTemplate = REVISED_SUMMARY_PROMPT,
190191
are_all_true_prompt: PromptTemplate = ARE_ALL_TRUE_PROMPT,
191-
verbose: bool = False,
192+
verbose: bool = False, # noqa: FBT001,FBT002
192193
**kwargs: Any,
193194
) -> LLMSummarizationCheckerChain:
194195
chain = _load_sequential_chain(

libs/langchain/langchain/chains/openai_functions/extraction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_extraction_chain(
8484
llm: BaseLanguageModel,
8585
prompt: Optional[BasePromptTemplate] = None,
8686
tags: Optional[list[str]] = None,
87-
verbose: bool = False,
87+
verbose: bool = False, # noqa: FBT001,FBT002
8888
) -> Chain:
8989
"""Creates a chain that extracts information from a passage.
9090
@@ -152,7 +152,7 @@ def create_extraction_chain_pydantic(
152152
pydantic_schema: Any,
153153
llm: BaseLanguageModel,
154154
prompt: Optional[BasePromptTemplate] = None,
155-
verbose: bool = False,
155+
verbose: bool = False, # noqa: FBT001,FBT002
156156
) -> Chain:
157157
"""Creates a chain that extracts information from a passage using pydantic schema.
158158

libs/langchain/langchain/chains/openai_functions/openapi.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323
from openapi_pydantic import Parameter
2424

2525

26-
def _get_description(o: Any, prefer_short: bool) -> Optional[str]:
27-
summary = getattr(o, "summary", None)
28-
description = getattr(o, "description", None)
29-
if prefer_short:
30-
return summary or description
31-
return description or summary
32-
33-
3426
def _format_url(url: str, path_params: dict) -> str:
3527
expected_path_param = re.findall(r"{(.*?)}", url)
3628
new_params = {}
@@ -260,7 +252,7 @@ def get_openapi_chain(
260252
prompt: Optional[BasePromptTemplate] = None,
261253
request_chain: Optional[Chain] = None,
262254
llm_chain_kwargs: Optional[dict] = None,
263-
verbose: bool = False,
255+
verbose: bool = False, # noqa: FBT001,FBT002
264256
headers: Optional[dict] = None,
265257
params: Optional[dict] = None,
266258
**kwargs: Any,

0 commit comments

Comments
 (0)