@@ -244,7 +244,7 @@ async def _messages_create(
244
244
except APIStatusError as e :
245
245
if (status_code := e .status_code ) >= 400 :
246
246
raise ModelHTTPError (status_code = status_code , model_name = self .model_name , body = e .body ) from e
247
- raise
247
+ raise # pragma: lax no cover
248
248
249
249
def _process_response (self , response : AnthropicMessage ) -> ModelResponse :
250
250
"""Process a non-streamed response, and prepare a message to return."""
@@ -268,7 +268,7 @@ async def _process_streamed_response(self, response: AsyncStream[RawMessageStrea
268
268
peekable_response = _utils .PeekableAsyncStream (response )
269
269
first_chunk = await peekable_response .peek ()
270
270
if isinstance (first_chunk , _utils .Unset ):
271
- raise UnexpectedModelBehavior ('Streamed response ended without content or tool calls' )
271
+ raise UnexpectedModelBehavior ('Streamed response ended without content or tool calls' ) # pragma: no cover
272
272
273
273
# Since Anthropic doesn't provide a timestamp in the message, we'll use the current time
274
274
timestamp = datetime .now (tz = timezone .utc )
@@ -305,9 +305,10 @@ async def _map_message(self, messages: list[ModelMessage]) -> tuple[str, list[Me
305
305
is_error = False ,
306
306
)
307
307
user_content_params .append (tool_result_block_param )
308
- elif isinstance (request_part , RetryPromptPart ):
308
+ elif isinstance (request_part , RetryPromptPart ): # pragma: no branch
309
309
if request_part .tool_name is None :
310
- retry_param = TextBlockParam (type = 'text' , text = request_part .model_response ())
310
+ text = request_part .model_response () # pragma: no cover
311
+ retry_param = TextBlockParam (type = 'text' , text = text ) # pragma: no cover
311
312
else :
312
313
retry_param = ToolResultBlockParam (
313
314
tool_use_id = _guard_tool_call_id (t = request_part ),
@@ -380,7 +381,7 @@ async def _map_user_prompt(
380
381
else : # pragma: no cover
381
382
raise RuntimeError (f'Unsupported media type: { item .media_type } ' )
382
383
else :
383
- raise RuntimeError (f'Unsupported content type: { type (item )} ' )
384
+ raise RuntimeError (f'Unsupported content type: { type (item )} ' ) # pragma: no cover
384
385
385
386
@staticmethod
386
387
def _map_tool_definition (f : ToolDefinition ) -> ToolParam :
@@ -447,21 +448,25 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
447
448
if isinstance (event , RawContentBlockStartEvent ):
448
449
current_block = event .content_block
449
450
if isinstance (current_block , TextBlock ) and current_block .text :
450
- yield self ._parts_manager .handle_text_delta (vendor_part_id = 'content' , content = current_block .text )
451
- elif isinstance (current_block , ToolUseBlock ):
451
+ yield self ._parts_manager .handle_text_delta ( # pragma: lax no cover
452
+ vendor_part_id = 'content' , content = current_block .text
453
+ )
454
+ elif isinstance (current_block , ToolUseBlock ): # pragma: no branch
452
455
maybe_event = self ._parts_manager .handle_tool_call_delta (
453
456
vendor_part_id = current_block .id ,
454
457
tool_name = current_block .name ,
455
458
args = cast (dict [str , Any ], current_block .input ),
456
459
tool_call_id = current_block .id ,
457
460
)
458
- if maybe_event is not None :
461
+ if maybe_event is not None : # pragma: no branch
459
462
yield maybe_event
460
463
461
464
elif isinstance (event , RawContentBlockDeltaEvent ):
462
465
if isinstance (event .delta , TextDelta ):
463
- yield self ._parts_manager .handle_text_delta (vendor_part_id = 'content' , content = event .delta .text )
464
- elif (
466
+ yield self ._parts_manager .handle_text_delta ( # pragma: no cover
467
+ vendor_part_id = 'content' , content = event .delta .text
468
+ )
469
+ elif ( # pragma: no branch
465
470
current_block and event .delta .type == 'input_json_delta' and isinstance (current_block , ToolUseBlock )
466
471
):
467
472
# Try to parse the JSON immediately, otherwise cache the value for later. This handles
@@ -480,7 +485,7 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
480
485
args = parsed_args ,
481
486
tool_call_id = current_block .id ,
482
487
)
483
- if maybe_event is not None :
488
+ if maybe_event is not None : # pragma: no branch
484
489
yield maybe_event
485
490
486
491
elif isinstance (event , (RawContentBlockStopEvent , RawMessageStopEvent )):
0 commit comments