Skip to content

Commit 69271c4

Browse files
committed
fix: resolve linting errors (N818, D101, UP038, SIM101, BLE001)
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
1 parent 81edd1e commit 69271c4

6 files changed

Lines changed: 58 additions & 20 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ def openapi(self) -> dict[str, Any]:
5151
# Try to use the a2a.json schema generated from the proto file
5252
# if available, instead of generating one from the python types.
5353
try:
54-
from a2a import types
54+
from a2a import types # noqa: PLC0415
5555

5656
schema_file = importlib.resources.files(types).joinpath('a2a.json')
5757
if schema_file.is_file():
5858
self.openapi_schema = json.loads(
5959
schema_file.read_text(encoding='utf-8')
6060
)
6161
return self.openapi_schema
62-
except Exception: # pylint: disable=broad-except
62+
except Exception: # noqa: BLE001
6363
logger.warning(
6464
"Could not load 'a2a.json' from 'a2a.types'. Falling back to auto-generation."
6565
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def _generate_error_response(
242242
Returns:
243243
A `JSONResponse` object formatted as a JSON-RPC error response.
244244
"""
245-
if not isinstance(error, (A2AException, JSONRPCError)):
245+
if not isinstance(error, A2AException | JSONRPCError):
246246
error = InternalError(message=str(error))
247247

248248
response_data = build_error_response(request_id, error)

src/a2a/server/events/event_consumer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ async def consume_all(self) -> AsyncGenerator[Event]:
102102
)
103103

104104
is_final_event = isinstance(event, Message) or (
105-
(
106-
isinstance(event, Task)
107-
or isinstance(event, TaskStatusUpdateEvent)
108-
)
105+
isinstance(event, Task | TaskStatusUpdateEvent)
109106
and event.status.state
110107
in (
111108
TaskState.TASK_STATE_COMPLETED,

src/a2a/server/jsonrpc_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
class JSONRPCBaseModel(BaseModel):
7+
"""Base model for JSON-RPC objects."""
8+
79
model_config = {
810
'extra': 'allow',
911
'populate_by_name': True,
@@ -12,31 +14,43 @@ class JSONRPCBaseModel(BaseModel):
1214

1315

1416
class JSONRPCError(JSONRPCBaseModel):
17+
"""Base model for JSON-RPC error objects."""
18+
1519
code: int
1620
message: str
1721
data: Any | None = None
1822

1923

2024
class JSONParseError(JSONRPCError):
25+
"""Error raised when invalid JSON was received by the server."""
26+
2127
code: Literal[-32700] = -32700
2228
message: str = 'Parse error'
2329

2430

2531
class InvalidRequestError(JSONRPCError):
32+
"""Error raised when the JSON sent is not a valid Request object."""
33+
2634
code: Literal[-32600] = -32600
2735
message: str = 'Invalid Request'
2836

2937

3038
class MethodNotFoundError(JSONRPCError):
39+
"""Error raised when the method does not exist / is not available."""
40+
3141
code: Literal[-32601] = -32601
3242
message: str = 'Method not found'
3343

3444

3545
class InvalidParamsError(JSONRPCError):
46+
"""Error raised when invalid method parameter(s)."""
47+
3648
code: Literal[-32602] = -32602
3749
message: str = 'Invalid params'
3850

3951

4052
class InternalError(JSONRPCError):
53+
"""Error raised when internal JSON-RPC error."""
54+
4155
code: Literal[-32603] = -32603
4256
message: str = 'Internal error'

src/a2a/server/request_handlers/response_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def prepare_response_object(
143143
result = MessageToDict(response, preserving_proto_field_name=False)
144144
return JSONRPC20Response(result=result, _id=request_id).data
145145

146-
if isinstance(response, (A2AException, JSONRPCError)):
146+
if isinstance(response, A2AException | JSONRPCError):
147147
return build_error_response(request_id, response)
148148

149149
# If response is not an expected success type and not an error,

src/a2a/utils/errors.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77

8-
class A2AException(Exception):
8+
class A2AError(Exception):
99
"""Base exception for A2A errors."""
1010

1111
message: str = 'A2A Error'
@@ -16,54 +16,81 @@ def __init__(self, message: str | None = None):
1616
super().__init__(self.message)
1717

1818

19-
class TaskNotFoundError(A2AException):
19+
class TaskNotFoundError(A2AError):
20+
"""Exception raised when a task is not found."""
21+
2022
message = 'Task not found'
2123

2224

23-
class TaskNotCancelableError(A2AException):
25+
class TaskNotCancelableError(A2AError):
26+
"""Exception raised when a task cannot be canceled."""
27+
2428
message = 'Task cannot be canceled'
2529

2630

27-
class PushNotificationNotSupportedError(A2AException):
31+
class PushNotificationNotSupportedError(A2AError):
32+
"""Exception raised when push notifications are not supported."""
33+
2834
message = 'Push Notification is not supported'
2935

3036

31-
class UnsupportedOperationError(A2AException):
37+
class UnsupportedOperationError(A2AError):
38+
"""Exception raised when an operation is not supported."""
39+
3240
message = 'This operation is not supported'
3341

3442

35-
class ContentTypeNotSupportedError(A2AException):
43+
class ContentTypeNotSupportedError(A2AError):
44+
"""Exception raised when the content type is incompatible."""
45+
3646
message = 'Incompatible content types'
3747

3848

39-
class InternalError(A2AException):
49+
class InternalError(A2AError):
50+
"""Exception raised for internal server errors."""
51+
4052
message = 'Internal error'
4153

4254

43-
class InvalidAgentResponseError(A2AException):
55+
class InvalidAgentResponseError(A2AError):
56+
"""Exception raised when the agent response is invalid."""
57+
4458
message = 'Invalid agent response'
4559

4660

47-
class AuthenticatedExtendedCardNotConfiguredError(A2AException):
61+
class AuthenticatedExtendedCardNotConfiguredError(A2AError):
62+
"""Exception raised when the authenticated extended card is not configured."""
63+
4864
message = 'Authenticated Extended Card is not configured'
4965

5066

51-
class InvalidParamsError(A2AException):
67+
class InvalidParamsError(A2AError):
68+
"""Exception raised when parameters are invalid."""
69+
5270
message = 'Invalid params'
5371

5472

55-
class InvalidRequestError(A2AException):
73+
class InvalidRequestError(A2AError):
74+
"""Exception raised when the request is invalid."""
75+
5676
message = 'Invalid Request'
5777

5878

59-
class MethodNotFoundError(A2AException):
79+
class MethodNotFoundError(A2AError):
80+
"""Exception raised when a method is not found."""
81+
6082
message = 'Method not found'
6183

6284

85+
# For backward compatibility
86+
A2AException = A2AError
87+
88+
6389
# For backward compatibility if needed, or just aliases for clean refactor
6490
# We remove the Pydantic models here.
6591

6692
__all__ = [
93+
'A2AError',
6794
'A2AException',
6895
'A2AServerError',
6996
'AuthenticatedExtendedCardNotConfiguredError',

0 commit comments

Comments
 (0)