Skip to content

Commit a2c61bf

Browse files
committed
Fix linting errors and remove dead code
1 parent 2125163 commit a2c61bf

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

pydantic_ai_slim/pydantic_ai/models/anthropic.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
BetaCacheControlEphemeralParam,
7070
BetaCitationsConfigParam,
7171
BetaCitationsDelta,
72+
BetaCodeExecutionTool20250522Param,
7273
BetaCodeExecutionToolResultBlock,
7374
BetaCodeExecutionToolResultBlockContent,
7475
BetaCodeExecutionToolResultBlockParam,
@@ -81,6 +82,7 @@
8182
BetaMCPToolResultBlock,
8283
BetaMCPToolUseBlock,
8384
BetaMCPToolUseBlockParam,
85+
BetaMemoryTool20250818Param,
8486
BetaMessage,
8587
BetaMessageParam,
8688
BetaMessageTokensCount,
@@ -158,8 +160,6 @@ class AnthropicModelSettings(ModelSettings, total=False):
158160
Contains `user_id`, an external identifier for the user who is associated with the request.
159161
"""
160162

161-
162-
163163
anthropic_thinking: BetaThinkingConfigParam
164164
"""Determine whether the model should generate a thinking block.
165165
@@ -409,21 +409,19 @@ async def _messages_create(
409409
extra_headers=extra_headers,
410410
extra_body=model_settings.get('extra_body'),
411411
)
412-
413-
# If streaming, return immediately
414-
if stream:
415-
return response
416-
412+
417413
# Handle pause_turn for non-streaming
418414
assert isinstance(response, BetaMessage)
419415
if response.stop_reason == 'pause_turn':
420416
# Append assistant message to history and continue
421-
anthropic_messages.append({
422-
'role': 'assistant',
423-
'content': response.content,
424-
})
417+
anthropic_messages.append(
418+
{
419+
'role': 'assistant',
420+
'content': response.content,
421+
}
422+
)
425423
continue
426-
424+
427425
return response
428426

429427
except APIStatusError as e:
@@ -501,8 +499,6 @@ async def _messages_count_tokens(
501499
except APIConnectionError as e:
502500
raise ModelAPIError(model_name=self.model_name, message=e.message) from e
503501

504-
505-
506502
def _process_response(self, response: BetaMessage) -> ModelResponse:
507503
"""Process a non-streamed response, and prepare a message to return."""
508504
items: list[ModelResponsePart] = []
@@ -558,7 +554,7 @@ def _process_response(self, response: BetaMessage) -> ModelResponse:
558554
if raw_finish_reason := response.stop_reason: # pragma: no branch
559555
provider_details = {'finish_reason': raw_finish_reason}
560556
finish_reason = _FINISH_REASON_MAP.get(raw_finish_reason)
561-
557+
562558
return ModelResponse(
563559
parts=items,
564560
usage=_map_usage(response, self._provider.name, self._provider.base_url, self._model_name),
@@ -1207,11 +1203,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
12071203
vendor_part_id=event.index,
12081204
part=_map_code_execution_tool_result_block(current_block, self.provider_name),
12091205
)
1210-
elif isinstance(current_block, BetaBashCodeExecutionToolResultBlock):
1211-
yield self._parts_manager.handle_part(
1212-
vendor_part_id=event.index,
1213-
part=_map_bash_code_execution_tool_result_block(current_block, self.provider_name),
1214-
)
1206+
12151207
elif isinstance(current_block, BetaWebFetchToolResultBlock): # pragma: lax no cover
12161208
yield self._parts_manager.handle_part(
12171209
vendor_part_id=event.index,
@@ -1410,19 +1402,3 @@ def _map_mcp_server_result_block(
14101402
content=item.model_dump(mode='json', include={'content', 'is_error'}),
14111403
tool_call_id=item.tool_use_id,
14121404
)
1413-
1414-
1415-
def _map_bash_code_execution_tool_result_block(
1416-
item: BetaBashCodeExecutionToolResultBlock, provider_name: str
1417-
) -> BuiltinToolReturnPart:
1418-
# We use the same content type adapter as code execution for now, assuming structure is similar
1419-
# or we might need a new one if `BetaBashCodeExecutionToolResultBlock` has different content structure.
1420-
# Assuming it's compatible or we can dump it as json.
1421-
# If `BetaBashCodeExecutionToolResultBlock` content is different, we should use its own type.
1422-
# But since we don't have a specific type adapter for it yet, we'll rely on model_dump.
1423-
return BuiltinToolReturnPart(
1424-
provider_name=provider_name,
1425-
tool_name=CodeExecutionTool.kind,
1426-
content=item.model_dump(mode='json', include={'content'}),
1427-
tool_call_id=item.tool_use_id,
1428-
)

0 commit comments

Comments
 (0)