Skip to content

Commit 303c206

Browse files
committed
Fix lint errors in rest_client
1 parent 3e2c623 commit 303c206

File tree

4 files changed

+90
-7
lines changed

4 files changed

+90
-7
lines changed

src/a2a/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
)
3434
from a2a.client.middleware import ClientCallContext, ClientCallInterceptor
3535
from a2a.client.rest_client import (
36-
NewRestfulClient,
3736
RestClient,
3837
RestTransportClient,
38+
new_restful_client,
3939
)
4040

4141

@@ -97,9 +97,9 @@ def __init__(self, *args, **kwargs):
9797
'JsonRpcTransportClient',
9898
'NewGrpcClient',
9999
'NewJsonRpcClient',
100-
'NewRestfulClient',
101100
'RestClient',
102101
'RestTransportClient',
103102
'create_text_message_object',
104103
'minimal_agent_card',
104+
'new_restful_client',
105105
]

src/a2a/client/client_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from a2a.client.grpc_client import NewGrpcClient
99
from a2a.client.jsonrpc_client import NewJsonRpcClient
1010
from a2a.client.middleware import ClientCallInterceptor
11-
from a2a.client.rest_client import NewRestfulClient
11+
from a2a.client.rest_client import new_restful_client
1212
from a2a.types import (
1313
AgentCapabilities,
1414
AgentCard,
@@ -61,7 +61,7 @@ def __init__(
6161
if TransportProtocol.jsonrpc in self._config.supported_transports:
6262
self._registry[TransportProtocol.jsonrpc] = NewJsonRpcClient
6363
if TransportProtocol.http_json in self._config.supported_transports:
64-
self._registry[TransportProtocol.http_json] = NewRestfulClient
64+
self._registry[TransportProtocol.http_json] = new_restful_client
6565
if TransportProtocol.grpc in self._config.supported_transports:
6666
self._registry[TransportProtocol.grpc] = NewGrpcClient
6767

src/a2a/client/rest_client.py

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ def __init__(
589589
def get_http_args(
590590
self, context: ClientCallContext
591591
) -> dict[str, Any] | None:
592+
"""Extract HTTP-specific keyword arguments from the client call context.
593+
594+
Args:
595+
context: The client call context.
596+
597+
Returns:
598+
A dictionary of HTTP arguments, or None.
599+
"""
592600
return context.state.get('http_kwargs', None) if context else None
593601

594602
async def send_message(
@@ -597,6 +605,18 @@ async def send_message(
597605
*,
598606
context: ClientCallContext | None = None,
599607
) -> AsyncIterator[Task | Message]:
608+
"""Send a message to the agent and consumes the response(s).
609+
610+
This method handles both blocking (non-streaming) and streaming responses
611+
based on the client configuration and agent capabilities.
612+
613+
Args:
614+
request: The message to send.
615+
context: The client call context.
616+
617+
Yields:
618+
The final message or task result from the agent.
619+
"""
600620
config = MessageSendConfiguration(
601621
accepted_output_modes=self._config.accepted_output_modes,
602622
blocking=not self._config.polling,
@@ -648,6 +668,15 @@ async def get_task(
648668
*,
649669
context: ClientCallContext | None = None,
650670
) -> Task:
671+
"""Retrieve a task from the agent.
672+
673+
Args:
674+
request: Parameters to identify the task.
675+
context: The client call context.
676+
677+
Returns:
678+
The requested task.
679+
"""
651680
return await self._transport_client.get_task(
652681
request,
653682
http_kwargs=self.get_http_args(context),
@@ -660,6 +689,15 @@ async def cancel_task(
660689
*,
661690
context: ClientCallContext | None = None,
662691
) -> Task:
692+
"""Cancel an ongoing task on the agent.
693+
694+
Args:
695+
request: Parameters to identify the task to cancel.
696+
context: The client call context.
697+
698+
Returns:
699+
The task after the cancellation request.
700+
"""
663701
return await self._transport_client.cancel_task(
664702
request,
665703
http_kwargs=self.get_http_args(context),
@@ -672,6 +710,15 @@ async def set_task_callback(
672710
*,
673711
context: ClientCallContext | None = None,
674712
) -> TaskPushNotificationConfig:
713+
"""Set a push notification callback for a task.
714+
715+
Args:
716+
request: The push notification configuration to set.
717+
context: The client call context.
718+
719+
Returns:
720+
The configured task push notification configuration.
721+
"""
675722
return await self._transport_client.set_task_callback(
676723
request,
677724
http_kwargs=self.get_http_args(context),
@@ -684,6 +731,15 @@ async def get_task_callback(
684731
*,
685732
context: ClientCallContext | None = None,
686733
) -> TaskPushNotificationConfig:
734+
"""Retrieve the push notification callback configuration for a task.
735+
736+
Args:
737+
request: Parameters to identify the task and configuration.
738+
context: The client call context.
739+
740+
Returns:
741+
The requested task push notification configuration.
742+
"""
687743
return await self._transport_client.get_task_callback(
688744
request,
689745
http_kwargs=self.get_http_args(context),
@@ -696,6 +752,20 @@ async def resubscribe(
696752
*,
697753
context: ClientCallContext | None = None,
698754
) -> AsyncIterator[Task | Message]:
755+
"""Resubscribe to a task's event stream.
756+
757+
This is only available if both the client and server support streaming.
758+
759+
Args:
760+
request: Parameters to identify the task to resubscribe to.
761+
context: The client call context.
762+
763+
Yields:
764+
Task events from the agent.
765+
766+
Raises:
767+
Exception: If streaming is not supported.
768+
"""
699769
if not self._config.streaming or not self._card.capabilities.streaming:
700770
raise Exception(
701771
'client and/or server do not support resubscription.'
@@ -713,17 +783,28 @@ async def get_card(
713783
*,
714784
context: ClientCallContext | None = None,
715785
) -> AgentCard:
786+
"""Retrieve the agent's card.
787+
788+
This may involve fetching the public card first if not already available,
789+
and then fetching the authenticated extended card if supported and required.
790+
791+
Args:
792+
context: The client call context.
793+
794+
Returns:
795+
The agent's card.
796+
"""
716797
return await self._transport_client.get_card(
717798
http_kwargs=self.get_http_args(context),
718799
context=context,
719800
)
720801

721802

722-
def NewRestfulClient(
803+
def new_restful_client(
723804
card: AgentCard,
724805
config: ClientConfig,
725806
consumers: list[Consumer],
726807
middleware: list[ClientCallInterceptor],
727808
) -> Client:
728-
"""Generator for the `RestClient` implementation."""
809+
"""Factory function for the `RestClient` implementation."""
729810
return RestClient(card, config, consumers, middleware)

src/a2a/server/apps/jsonrpc/fastapi_app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def add_routes_to_app(
8787
}
8888
},
8989
)(self._handle_requests)
90-
app.get(agent_card_url)(self._handle_get_agent_card)
90+
app.get(agent_card_url)(
91+
self._handle_get_agent_card # ruff noqa: SLF001
92+
)
9193

9294
if self.agent_card.supports_authenticated_extended_card:
9395
app.get(extended_agent_card_url)(

0 commit comments

Comments
 (0)