Skip to content

Commit 63efd73

Browse files
committed
Fix lint errors
1 parent c8d96f8 commit 63efd73

File tree

14 files changed

+88
-35
lines changed

14 files changed

+88
-35
lines changed

.github/linters/.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ignore = [
2828
"E501", # Ignore line length (handled by Ruff's dynamic line length)
2929
"ANN002",
3030
"ANN003",
31+
"ANN401",
3132
]
3233

3334
select = [

src/a2a/auth/user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ class UnauthenticatedUser(User):
2222

2323
@property
2424
def is_authenticated(self) -> bool:
25+
"""Returns whether the current user is authenticated."""
2526
return False
2627

2728
@property
2829
def user_name(self) -> str:
30+
"""Returns the user name of the current user."""
2931
return ''

src/a2a/server/agent_execution/agent_executor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class AgentExecutor(ABC):
1212
"""
1313

1414
@abstractmethod
15-
async def execute(self, context: RequestContext, event_queue: EventQueue):
15+
async def execute(
16+
self, context: RequestContext, event_queue: EventQueue
17+
) -> None:
1618
"""Execute the agent's logic for a given request context.
1719
1820
The agent should read necessary information from the `context` and
@@ -27,7 +29,9 @@ async def execute(self, context: RequestContext, event_queue: EventQueue):
2729
"""
2830

2931
@abstractmethod
30-
async def cancel(self, context: RequestContext, event_queue: EventQueue):
32+
async def cancel(
33+
self, context: RequestContext, event_queue: EventQueue
34+
) -> None:
3135
"""Request the agent to cancel an ongoing task.
3236
3337
The agent should attempt to stop the task identified by the task_id

src/a2a/server/agent_execution/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RequestContext:
2020
tasks.
2121
"""
2222

23-
def __init__(
23+
def __init__( # noqa: PLR0913
2424
self,
2525
request: MessageSendParams | None = None,
2626
task_id: str | None = None,
@@ -37,6 +37,7 @@ def __init__(
3737
context_id: The ID of the context explicitly provided in the request or path.
3838
task: The existing `Task` object retrieved from the store, if any.
3939
related_tasks: A list of other tasks related to the current request (e.g., for tool use).
40+
call_context: The server call context associated with this request.
4041
"""
4142
if related_tasks is None:
4243
related_tasks = []
@@ -64,7 +65,7 @@ def __init__(
6465
else:
6566
self._check_or_generate_context_id()
6667

67-
def get_user_input(self, delimiter='\n') -> str:
68+
def get_user_input(self, delimiter: str = '\n') -> str:
6869
"""Extracts text content from the user's message parts.
6970
7071
Args:

src/a2a/server/agent_execution/simple_request_context_builder.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ def __init__(
1414
should_populate_referred_tasks: bool = False,
1515
task_store: TaskStore | None = None,
1616
) -> None:
17+
"""Initializes the SimpleRequestContextBuilder.
18+
19+
Args:
20+
should_populate_referred_tasks: If True, the builder will fetch tasks
21+
referenced in `params.message.referenceTaskIds` and populate the
22+
`related_tasks` field in the RequestContext. Defaults to False.
23+
task_store: The TaskStore instance to use for fetching referred tasks.
24+
Required if `should_populate_referred_tasks` is True.
25+
"""
26+
if should_populate_referred_tasks and not task_store:
27+
raise ValueError(
28+
'task_store is required when should_populate_referred_tasks is True'
29+
)
1730
self._task_store = task_store
1831
self._should_populate_referred_tasks = should_populate_referred_tasks
1932

@@ -25,6 +38,23 @@ async def build(
2538
task: Task | None = None,
2639
context: ServerCallContext | None = None,
2740
) -> RequestContext:
41+
"""Builds the request context for an agent execution.
42+
43+
This method assembles the RequestContext object. If the builder was
44+
initialized with `should_populate_referred_tasks=True`, it fetches all tasks
45+
referenced in `params.message.referenceTaskIds` from the `task_store`.
46+
47+
Args:
48+
params: The parameters of the incoming message send request.
49+
task_id: The ID of the task being executed.
50+
context_id: The ID of the current execution context.
51+
task: The primary task object associated with the request.
52+
context: The server call context, containing metadata about the call.
53+
54+
Returns:
55+
An instance of RequestContext populated with the provided information
56+
and potentially a list of related tasks.
57+
"""
2858
related_tasks: list[Task] | None = None
2959

3060
if (

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any
44

5-
from fastapi import FastAPI, Request
5+
from fastapi import FastAPI, Request, Response
66

77
from a2a.server.apps.jsonrpc.jsonrpc_app import (
88
CallContextBuilder,
@@ -70,17 +70,17 @@ def build(
7070
app = FastAPI(**kwargs)
7171

7272
@app.post(rpc_url)
73-
async def handle_a2a_request(request: Request):
73+
async def handle_a2a_request(request: Request) -> Response:
7474
return await self._handle_requests(request)
7575

7676
@app.get(agent_card_url)
77-
async def get_agent_card(request: Request):
77+
async def get_agent_card(request: Request) -> Response:
7878
return await self._handle_get_agent_card(request)
7979

8080
if self.agent_card.supportsAuthenticatedExtendedCard:
8181

8282
@app.get(extended_agent_card_url)
83-
async def get_extended_agent_card(request: Request):
83+
async def get_extended_agent_card(request: Request) -> Response:
8484
return await self._handle_get_authenticated_extended_agent_card(
8585
request
8686
)

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ def __init__(self, user: BaseUser):
5353
self._user = user
5454

5555
@property
56-
def is_authenticated(self):
56+
def is_authenticated(self) -> bool:
57+
"""Returns whether the current user is authenticated."""
5758
return self._user.is_authenticated
5859

5960
@property
60-
def user_name(self):
61+
def user_name(self) -> str:
62+
"""Returns the user name of the current user."""
6163
return self._user.display_name
6264

6365

@@ -73,7 +75,16 @@ class DefaultCallContextBuilder(CallContextBuilder):
7375
"""A default implementation of CallContextBuilder."""
7476

7577
def build(self, request: Request) -> ServerCallContext:
76-
user = UnauthenticatedUser()
78+
"""Builds a ServerCallContext from a Starlette Request.
79+
80+
Args:
81+
request: The incoming Starlette Request object.
82+
83+
Returns:
84+
A ServerCallContext instance populated with user and state
85+
information from the request.
86+
"""
87+
user: A2AUser = UnauthenticatedUser()
7788
state = {}
7889
with contextlib.suppress(Exception):
7990
user = StarletteUserProxy(request.user)
@@ -232,6 +243,7 @@ async def _process_streaming_request(
232243
Args:
233244
request_id: The ID of the request.
234245
a2a_request: The validated A2ARequest object.
246+
context: The ServerCallContext for the request.
235247
236248
Returns:
237249
An `EventSourceResponse` object to stream results to the client.
@@ -263,6 +275,7 @@ async def _process_non_streaming_request(
263275
Args:
264276
request_id: The ID of the request.
265277
a2a_request: The validated A2ARequest object.
278+
context: The ServerCallContext for the request.
266279
267280
Returns:
268281
A `JSONResponse` object containing the result or error.

src/a2a/server/events/queue_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class QueueManager(ABC):
77
"""Interface for managing the event queue lifecycles per task."""
88

99
@abstractmethod
10-
async def add(self, task_id: str, queue: EventQueue):
10+
async def add(self, task_id: str, queue: EventQueue) -> None:
1111
"""Adds a new event queue associated with a task ID."""
1212

1313
@abstractmethod
@@ -19,17 +19,17 @@ async def tap(self, task_id: str) -> EventQueue | None:
1919
"""Creates a child event queue (tap) for an existing task ID."""
2020

2121
@abstractmethod
22-
async def close(self, task_id: str):
22+
async def close(self, task_id: str) -> None:
2323
"""Closes and removes the event queue for a task ID."""
2424

2525
@abstractmethod
2626
async def create_or_tap(self, task_id: str) -> EventQueue:
2727
"""Creates a queue if one doesn't exist, otherwise taps the existing one."""
2828

2929

30-
class TaskQueueExists(Exception):
30+
class TaskQueueExists(Exception): # noqa: N818
3131
"""Exception raised when attempting to add a queue for a task ID that already exists."""
3232

3333

34-
class NoTaskQueue(Exception):
34+
class NoTaskQueue(Exception): # noqa: N818
3535
"""Exception raised when attempting to access or close a queue for a task ID that does not exist."""

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ async def on_message_send(
235235
finally:
236236
if interrupted:
237237
# TODO: Track this disconnected cleanup task.
238-
asyncio.create_task(
238+
asyncio.create_task( # noqa: RUF006
239239
self._cleanup_producer(producer_task, task_id)
240240
)
241241
else:
@@ -427,6 +427,7 @@ async def on_resubscribe_to_task(
427427
yield event
428428

429429
def should_add_push_info(self, params: MessageSendParams) -> bool:
430+
"""Determines if push notification info should be set for a task."""
430431
return bool(
431432
self._push_notifier
432433
and params.configuration

src/a2a/server/tasks/push_notifier.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class PushNotifier(ABC):
99
@abstractmethod
1010
async def set_info(
1111
self, task_id: str, notification_config: PushNotificationConfig
12-
):
12+
) -> None:
1313
"""Sets or updates the push notification configuration for a task."""
1414

1515
@abstractmethod
1616
async def get_info(self, task_id: str) -> PushNotificationConfig | None:
1717
"""Retrieves the push notification configuration for a task."""
1818

1919
@abstractmethod
20-
async def delete_info(self, task_id: str):
20+
async def delete_info(self, task_id: str) -> None:
2121
"""Deletes the push notification configuration for a task."""
2222

2323
@abstractmethod
24-
async def send_notification(self, task: Task):
24+
async def send_notification(self, task: Task) -> None:
2525
"""Sends a push notification containing the latest task state."""

0 commit comments

Comments
 (0)