Skip to content

Commit 645e25f

Browse files
authored
langchain-anthropic[patch]: Add ruff bandit rules (#31789)
1 parent 247673d commit 645e25f

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

libs/partners/anthropic/langchain_anthropic/_client_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __del__(self) -> None:
2525

2626
try:
2727
self.close()
28-
except Exception:
28+
except Exception: # noqa: S110
2929
pass
3030

3131

@@ -39,7 +39,7 @@ def __del__(self) -> None:
3939
try:
4040
# TODO(someday): support non asyncio runtimes here
4141
asyncio.get_running_loop().create_task(self.aclose())
42-
except Exception:
42+
except Exception: # noqa: S110
4343
pass
4444

4545

libs/partners/anthropic/langchain_anthropic/chat_models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ def _format_messages(
327327

328328
if not isinstance(message.content, str):
329329
# parse as dict
330-
assert isinstance(
331-
message.content, list
332-
), "Anthropic message content must be str or list of dicts"
330+
if not isinstance(message.content, list):
331+
raise ValueError(
332+
"Anthropic message content must be str or list of dicts"
333+
)
333334

334335
# populate content
335336
content = []

libs/partners/anthropic/pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ plugins = ['pydantic.mypy']
6060
target-version = "py39"
6161

6262
[tool.ruff.lint]
63-
select = ["E", "F", "I", "T201", "UP"]
63+
select = ["E", "F", "I", "T201", "UP", "S"]
6464
ignore = [ "UP007", ]
6565

6666
[tool.coverage.run]
@@ -73,3 +73,9 @@ markers = [
7373
"compile: mark placeholder test used to compile integration tests without running them",
7474
]
7575
asyncio_mode = "auto"
76+
77+
[tool.ruff.lint.extend-per-file-ignores]
78+
"tests/**/*.py" = [
79+
"S101", # Tests need assertions
80+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
81+
]

libs/partners/anthropic/tests/integration_tests/test_chat_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def test_anthropic_bind_tools_tool_choice(tool_choice: str) -> None:
651651

652652
def test_pdf_document_input() -> None:
653653
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
654-
data = b64encode(requests.get(url).content).decode()
654+
data = b64encode(requests.get(url, timeout=10).content).decode()
655655

656656
result = ChatAnthropic(model=IMAGE_MODEL_NAME).invoke(
657657
[

libs/partners/anthropic/tests/unit_tests/test_chat_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,4 +1071,4 @@ def mock_create(*args: Any, **kwargs: Any) -> Message:
10711071

10721072
# Test headers are correctly propagated to request
10731073
payload = llm._get_request_payload([input_message])
1074-
assert payload["mcp_servers"][0]["authorization_token"] == "PLACEHOLDER"
1074+
assert payload["mcp_servers"][0]["authorization_token"] == "PLACEHOLDER" # noqa: S105

0 commit comments

Comments
 (0)