Skip to content

Commit 519263e

Browse files
foleydangclaude
andcommitted
fix: resolve pre-commit lint issues (black, flake8, pylint)
- Reformat with black (line-length 79) - Fix extra blank line in transport.py - Wrap docstrings within 79 chars - Suppress pylint missing-kwoa in intentional negative test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 952d7fb commit 519263e

3 files changed

Lines changed: 54 additions & 38 deletions

File tree

dashscope/agentstudio/resources/agents.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66

77
from typing import Any, Mapping, Optional, Sequence
88

9-
from dashscope.agentstudio.pagination import (AsyncCursorPage, CursorPage,
10-
build_page)
11-
from dashscope.agentstudio.resources._helpers import (_coerce_agent,
12-
_coerce_agent_version)
9+
from dashscope.agentstudio.pagination import (
10+
AsyncCursorPage,
11+
CursorPage,
12+
build_page,
13+
)
14+
from dashscope.agentstudio.resources._helpers import (
15+
_coerce_agent,
16+
_coerce_agent_version,
17+
)
1318
from dashscope.agentstudio.types import Agent, AgentVersion
14-
from dashscope.agentstudio.types.params import (AgentCreateParams,
15-
AgentListParams,
16-
AgentUpdateParams,
17-
AgentVersionListParams)
19+
from dashscope.agentstudio.types.params import (
20+
AgentCreateParams,
21+
AgentListParams,
22+
AgentUpdateParams,
23+
AgentVersionListParams,
24+
)
1825

1926
_PATH_AGENTS = "/agents"
2027

@@ -86,9 +93,9 @@ def update(
8693
) -> Agent:
8794
"""Update the latest version of an agent.
8895
89-
``version`` must equal the server's current version; the server rejects mismatches with
90-
HTTP 409. Call ``retrieve(agent_id)`` first to obtain the current version — the SDK does
91-
not auto-resolve it.
96+
``version`` must equal the server's current version;
97+
the server rejects mismatches with HTTP 409.
98+
Retrieve the agent first to obtain the current version.
9299
"""
93100
body = AgentUpdateParams(
94101
version=version,
@@ -239,9 +246,9 @@ async def update(
239246
) -> Agent:
240247
"""Update the latest version of an agent.
241248
242-
``version`` must equal the server's current version; the server rejects mismatches with
243-
HTTP 409. Call ``retrieve(agent_id)`` first to obtain the current version — the SDK does
244-
not auto-resolve it.
249+
``version`` must equal the server's current version;
250+
the server rejects mismatches with HTTP 409.
251+
Retrieve the agent first to obtain the current version.
245252
"""
246253
body = AgentUpdateParams(
247254
version=version,

dashscope/agentstudio/transport.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def is_error_payload(payload: Any) -> bool:
131131
return False
132132

133133

134-
135134
def _resolve_timeout(
136135
timeout: Union[float, httpx.Timeout, Tuple[float, float], None],
137136
) -> httpx.Timeout:
@@ -377,16 +376,16 @@ def request( # pylint: disable=too-many-branches
377376
else:
378377
return resp
379378
if _should_retry(
380-
resp.status_code, resp.headers,
379+
resp.status_code,
380+
resp.headers,
381381
):
382382
last_exc = exceptions.APIStatusError(
383383
f"HTTP {resp.status_code}",
384384
status_code=resp.status_code,
385385
)
386386
if attempt < self.max_retries:
387-
wait = (
388-
_get_retry_after(resp.headers)
389-
or _backoff(attempt)
387+
wait = _get_retry_after(resp.headers) or _backoff(
388+
attempt
390389
)
391390
resp.close()
392391
time.sleep(wait)
@@ -601,16 +600,16 @@ async def request( # pylint: disable=too-many-branches
601600
else:
602601
return resp
603602
if _should_retry(
604-
resp.status_code, resp.headers,
603+
resp.status_code,
604+
resp.headers,
605605
):
606606
last_exc = exceptions.APIStatusError(
607607
f"HTTP {resp.status_code}",
608608
status_code=resp.status_code,
609609
)
610610
if attempt < self.max_retries:
611-
wait = (
612-
_get_retry_after(resp.headers)
613-
or _backoff(attempt)
611+
wait = _get_retry_after(resp.headers) or _backoff(
612+
attempt
614613
)
615614
await resp.aclose()
616615
await asyncio.sleep(wait)

tests/unit/test_agentstudio_protocol.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
from dashscope.agentstudio import exceptions
2222
from dashscope.agentstudio.transport import is_error_payload, unwrap
23-
from dashscope.agentstudio.types import (user_custom_tool_result,
24-
user_define_outcome, user_interrupt,
25-
user_message, user_tool_confirmation)
23+
from dashscope.agentstudio.types import (
24+
user_custom_tool_result,
25+
user_define_outcome,
26+
user_interrupt,
27+
user_message,
28+
user_tool_confirmation,
29+
)
2630

2731
# ---------------------------------------------------------------------------
2832
# 1. error.{code, message}
@@ -303,16 +307,24 @@ def _client_with_recording_transport():
303307

304308

305309
def test_agents_update_requires_version_kwarg():
306-
"""version is a required keyword-only argument — omitting it is a TypeError."""
310+
"""version is required — omitting it is a TypeError."""
307311
client = _client_with_recording_transport()
308312
with pytest.raises(TypeError):
309-
client.agents.update("agent_1", name="new-name") # type: ignore[call-arg]
313+
# pylint: disable=missing-kwoa
314+
client.agents.update( # type: ignore[call-arg]
315+
"agent_1",
316+
name="new-name",
317+
)
310318

311319

312320
def test_agents_update_with_version_sends_body():
313-
"""update(agent_id, version=...) sends POST /agents/{id} with version in body."""
321+
"""update() sends POST /agents/{id} with version."""
314322
client = _client_with_recording_transport()
315-
client.agents.update("agent_1", version=3, name="new-name")
323+
client.agents.update(
324+
"agent_1",
325+
version=3,
326+
name="new-name",
327+
)
316328
assert len(client.transport.calls) == 1
317329
call = client.transport.calls[0]
318330
assert call["method"] == "POST"
@@ -323,14 +335,12 @@ def test_agents_update_with_version_sends_body():
323335

324336

325337
def test_agents_update_does_not_auto_retrieve():
326-
"""SDK must NOT call retrieve() internally — caller manages version now.
327-
328-
Mirrors the Anthropic Managed Agents SDK: the server only accepts updates
329-
against the latest version (409 on mismatch), so the caller is responsible
330-
for retrieving the current version first.
331-
"""
338+
"""SDK must NOT call retrieve() internally."""
332339
client = _client_with_recording_transport()
333-
client.agents.update("agent_1", version=3, name="new-name")
334-
# Only the POST should be recorded, no preceding GET.
340+
client.agents.update(
341+
"agent_1",
342+
version=3,
343+
name="new-name",
344+
)
335345
assert len(client.transport.calls) == 1
336346
assert client.transport.calls[0]["method"] == "POST"

0 commit comments

Comments
 (0)