ruff: add bugbear across packages (#31917)

WIP, other packages will get in next PRs
This commit is contained in:
Mason Daugherty
2025-07-08 12:22:55 -04:00
committed by GitHub
parent 5b3e29f809
commit ae210c1590
33 changed files with 59 additions and 42 deletions

View File

@@ -314,7 +314,7 @@ def _format_messages(
system: Union[str, list[dict], None] = None
formatted_messages: list[dict] = []
merged_messages = _merge_messages(messages)
for i, message in enumerate(merged_messages):
for _i, message in enumerate(merged_messages):
if message.type == "system":
if system is not None:
msg = "Received multiple non-consecutive system messages."
@@ -496,7 +496,7 @@ def _handle_anthropic_bad_request(e: anthropic.BadRequestError) -> None:
"""Handle Anthropic BadRequestError."""
if ("messages: at least one message is required") in e.message:
message = "Received only system message(s). "
warnings.warn(message)
warnings.warn(message, stacklevel=2)
raise e
raise
@@ -1558,7 +1558,7 @@ class ChatAnthropic(BaseChatModel):
"generated. Consider disabling `thinking` or adjust your prompt to ensure "
"the tool is called."
)
warnings.warn(thinking_admonition)
warnings.warn(thinking_admonition, stacklevel=2)
llm = self.bind_tools(
[schema],
ls_structured_output_format={
@@ -2120,7 +2120,7 @@ def _make_message_chunk_from_anthropic_event(
)
):
if coerce_content_to_string:
warnings.warn("Received unexpected tool content block.")
warnings.warn("Received unexpected tool content block.", stacklevel=2)
content_block = event.content_block.model_dump()
content_block["index"] = event.index
if event.content_block.type == "tool_use":

View File

@@ -170,6 +170,7 @@ class AnthropicLLM(LLM, _AnthropicCommon):
"This Anthropic LLM is deprecated. "
"Please use `from langchain_anthropic import ChatAnthropic` "
"instead",
stacklevel=2,
)
return values

View File

@@ -62,6 +62,7 @@ target-version = "py39"
[tool.ruff.lint]
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"ASYNC", # flake8-async
"C4", # flake8-comprehensions
"COM", # flake8-commas

View File

@@ -1210,6 +1210,5 @@ def test_search_result_top_level() -> None:
def test_async_shared_client() -> None:
llm = ChatAnthropic(model="claude-3-5-haiku-latest")
llm._async_client # Instantiates lazily
_ = asyncio.run(llm.ainvoke("Hello"))
_ = asyncio.run(llm.ainvoke("Hello"))