Skip to content

Commit 1c27cd0

Browse files
authored
chore: improve typing for select_streaming_callback (#2008)
1 parent 0f0cbe7 commit 1c27cd0

File tree

3 files changed

+7
-9
lines changed
  • integrations
    • amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat
    • anthropic/src/haystack_integrations/components/generators/anthropic/chat
    • cohere/src/haystack_integrations/components/generators/cohere/chat

3 files changed

+7
-9
lines changed

integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ def _prepare_request_params(
371371
if additional_fields:
372372
params["additionalModelRequestFields"] = additional_fields
373373

374-
callback = select_streaming_callback(
374+
# overloads that exhaust finite Literals(bool) not treated as exhaustive
375+
# see https://github.com/python/mypy/issues/14764
376+
callback = select_streaming_callback( # type: ignore[call-overload]
375377
init_callback=self.streaming_callback,
376378
runtime_callback=streaming_callback,
377379
requires_async=requires_async,

integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ def run(
633633
**generation_kwargs,
634634
)
635635

636-
# select_streaming_callback returns a StreamingCallbackT, but we know it's SyncStreamingCallbackT
637-
return self._process_response(response=response, streaming_callback=streaming_callback) # type: ignore[arg-type]
636+
return self._process_response(response=response, streaming_callback=streaming_callback)
638637

639638
@component.output_types(replies=List[ChatMessage])
640639
async def run_async(
@@ -675,5 +674,4 @@ async def run_async(
675674
**generation_kwargs,
676675
)
677676

678-
# select_streaming_callback returns a StreamingCallbackT, but we know it's AsyncStreamingCallbackT
679-
return await self._process_response_async(response, streaming_callback) # type: ignore[arg-type]
677+
return await self._process_response_async(response, streaming_callback)

integrations/cohere/src/haystack_integrations/components/generators/cohere/chat/chat_generator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,10 @@ def run(
528528
messages=formatted_messages,
529529
**generation_kwargs,
530530
)
531-
# we know that streaming_callback is sync but mypy doesn't
532531
chat_message = _parse_streaming_response(
533532
response=streamed_response,
534533
model=self.model,
535-
streaming_callback=streaming_callback, # type: ignore[arg-type]
534+
streaming_callback=streaming_callback,
536535
)
537536
else:
538537
response = self.client.chat(
@@ -590,11 +589,10 @@ async def run_async(
590589
messages=formatted_messages,
591590
**generation_kwargs,
592591
)
593-
# we know that streaming_callback is async but mypy doesn't
594592
chat_message = await _parse_async_streaming_response(
595593
response=streamed_response,
596594
model=self.model,
597-
streaming_callback=streaming_callback, # type: ignore[arg-type]
595+
streaming_callback=streaming_callback,
598596
)
599597
else:
600598
response = await self.async_client.chat(

0 commit comments

Comments
 (0)